Copy entities on automation execution

Hi all, I have an automation that at certain conditions performs operations on some orders. Let me give an example.

I have Orders database that has a one-to-many relation with Items.
I have an Orders entity, say Order1, that is related to two items entyties, Item1 and Item2.

When the field Status of Order1 entity changes to “Renegotiated” I want do the following:

  1. Entity Order1 be copied to Order2
  2. Entities Item1 and Item2 be copied to Item3 and Item4
  3. Entity Order2 be related to Item3 and Item4

This is needed to let apply changes to Order2 items that do not reflect on Order1 items.
I’ve tried to assign Order1.Items to Order2.Items but this “detach” Item1 and Item2 from Order1 and “attach” them to Order2, leaving Order1 empty.

Many-to-many relation is not an option because of changes to Order2 items reflected to Order1 and viceversa.

Any idea on how to obtain this? Thankyou to all.

It sounds like you basically want to duplicate an order and the items it contains, right?
Here’s how I would suggest you do it:

Add a new relation (many-to-one) between Item and Order, and call it something like ‘Duplicate order’:

(you should probably hide this field and it’s opposite on entity view)

Define an automation in the Item database that will create a duplicate Item when this new field is populated:

Add a new relation (one-to-one) between Order and Order, and call it something like ‘New order’:

(you should probably hide this field and it’s opposite on entity view)

Define an automation in the Order database to create a new Order AND to trigger the Duplicate automation for each Item, by linking this new Order to them:

Let us know if that works :slight_smile:

Note:

It’s up to you whether or not you want to also clear the ‘helper’ fields after the automation actions have run:

If you don’t, then you will be able to see that the old and new entities are linked together, but you won’t be able to re-run the automation for any given Order/Item.
If it is possible that you need the duplication to happen more than once (i.e. if an Order will enter the Renegotiated state more than once) then you will need to clear the fields.

Good luck!

1 Like

Thankyou @Chr1sG , your solution works perfectly. I’m new to Fibery and learned e bit more about how Fibery works.

1 Like