Updating and creating entities with one follow-up form

Boring stuff

I tried multiple ways to write the entity_id expression, and none have worked for the 'create' case, but all work for the 'update' case. ${item_to_update} is the selected entity list item, ${action} is the question to either create or update

Tested in Enketo (update worked, create didn't)

  • coalesce(${item_to_update}, uuid())
  • if(${item_to_update}!='',${item_to_update},uuid())
  • if(${action}='update',${item_to_update},uuid())

Tested in Collect (update worked, create didn't)

  • if(${action}='update',${item_to_update},uuid())

And, then I looked at the example linked in this thread and saw two other columns create_if and update_if! These are in the docs, but aren't in the 'trees' example form linked from the docs and the docs don't indicate that you must have them to allow change/update functionality @LN.

So I added ${action}='update' to update_if and ${action}='add' to create_if and reverted to entity_id = coalesce(${item_to_update}, uuid()), works in Enketo for create & update! :confetti_ball:

For others - the docs aren't explicit - if you want to either create OR update in a single form, you must have create_if and update_if columns in the entities sheet of your form, with expressions that evaluate for those cases. Then the entity_id column must also have an expression to return the ID of the item being updated or generate a UUID if being created. eg

  • create_if
    • ${create_or_update}='create'
  • update_if
    • ${create_or_update}='update'
  • entity_id
    • coalesce(${existing_item},uuid())
1 Like