UPSERT update triggers RecordCreated state workflow

I was trying to …

  1. I use one form with Staging entity to update Target entity using action button Transfer
  2. Workflow is modelled in very simple way - I transform the Staging entity into Target entity using just data inside Staging entity because it has reference lookup to target entity.
  3. To save values, I use Data Structure with UPSERT option enabled on entity.
  4. On the target entity, there is Workflow OnRecordCreated
  5. I edit staging entity and press button transfer

I was expecting …

  1. Updating values inside Target entity.
  2. I expect state workflowOnRecordCreated wouldn’t be executed. There is serial number generation and my Target entity record is getting renumbered

Instead I’ve got …

  1. :white_check_mark: Updating values inside Target entity.
  2. :x: I expect state workflowOnRecordCreated wouldn’t be executed.

Workaround

Generate new serial number only if the field is not filled.

Notes

I have a workaround inside my solution, so it is not an urgent issue, but I believe UPSERT when doing update should not call OnRecordCreated state workflow.

I can model it into model-tests but into which package it should go? Into automated tests?

This is interesting. So the whole idea of UPSERT is that we DON’T KNOW if the value will be inserted or updated, we just leave it on the generated SQL statement. I think currently there is no way how to detect which kind of event (created or updated) to call.

So internally it’s a kind of INSERT which does not fail if the record already exists. That explains why OnRecordCreated gets called although I understand that it is controversial.