Hi @EduardoCM!
Thank you for sharing your form! I have modified your form to hopefully create and update entities in the way you need.
update_entities_updated.xlsx (53.9 KB)
Steps:
1. Add a question to optionally select an existing entity
In your case, the entity list is called eventos
so we could have a question like
type |
name |
label |
select_one_from_file eventos.csv |
evento_existente_id |
Seleccione un evento existente para editarlo |
This will capture the ID of the existing entity to edit, which we can use to hook up everything else.
If no entity is selected, then the form will create a new entity.
2. Fill in the default value for each field on the form with the data from that entity. You will need to make a change to every row that has a save_to
value filled in.
- Add a
trigger
column and fill it with ${evento_existente_id}
- Fill in
calculation
for every row with a save_to
with a formula like instance("eventos")/root/item[name=${evento_existente_id}]/tipo_evento
3. Update the entities
tab to add rules about how to create or update the entity, and how to identify the updated entity:
create_if |
update_if |
entity_id |
${evento_existente_id} = '' |
${evento_existente_id} != '' |
coalesce(${evento_existente_id}, uuid()) |
The coalesce
expression is needed for this combined create/update form because the form generates the entity ID. (Otherwise, when a form only creates or only updates entities, this ID is set implicitly.)
4. For the part of the form where you are saving values from a cascade select, I added redes_locale
as an entity property so it could be used to look up the values later
Additionally, when I tried to create and then edit one of these events, not every value was filled in, but I think it is because those fields were just not saved to entity properties and they could easily be added if you definitely wanted to edit them later.
This was a useful exercise for me to do! It was a little tricky even having the entity quick reference to refer to. I think it could also be the topic of a mini-tutorial about entities -- how to take a form for creating entities and transform it into a form that can also update them. If there is anything about this form that doesn't work, please let me know!