Updating and creating entities with one follow-up form


I am testing entities for our purposes. To this purpose I have created a form that creates an entity list of the enumerators to replace the .csv file we are using at the moment.

This forms works fine and entities are correctly created.

I have build a second form very similar to the first to modify the entities. Works fine as well.

For simplicity reasons I now want to use the same form to update AND create new entities in the same entity list. This fails.

To find the error I have removed in the entities tap the label column. In this case, the form manages to create new entities but cannot modify existing entries. It seems as if updating and creating new entities is not possible with the same form, although this procedure is descibed in the tutorial:

Creating AND Updating Entities with one Form
You can give both a create_if and an update_if rule for the same Form. If only one of these expression evaluates to true or 1, then only that operation will be carried out. If both rules evaluate to true or 1, the Entity will be created if it does not exist (as identified by the entity_id expression), and updated if it does. Of course, if neither rule evaluates to true or 1, no Entity changes will occur.

I attach the xlsform.

Thanks you for any help.

Best, Daniel
admin_inspecteur.xlsx (13.0 KB)

Currently your entity_id expression needs to explicitly generate an id in the create case. You can do this with an expression like if(${inspecteur_code_existant='', uuid(), ${inspecteur_code_existant}).

Another way to express this same idea is using the coalesce function: coalesce(${inspecteur_code_existant}, uuid())

I think you were getting at a similar idea with inspecteur_code but that is a user-provided code, not a system ID. You can have both but each entity must have a UUID as its entity_id.

Here's a similar example you may find helpful: https://docs.google.com/spreadsheets/d/1poe2lx_MUzbN0ySuZlRX8_fuKqM4LdsBMwKORQW1QRk I'll work to improve docs around this case.

1 Like

Thanks LN! I'll try your solution as soon as possible and give a reply.

Thanks Great help for same problem.

1 Like