# Batch Operations: Reference Sibling Operation Results

**URL:** <https://community.fibery.io/t/batch-operations-reference-sibling-operation-results/5286>\
**Category:** API & Programming\
**Created:** [October 12, 2023, 4:02pm UTC](https://community.fibery.io/t/batch-operations-reference-sibling-operation-results/5286 "2023-10-12T16:02:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![carson](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/carson/32/7503_2.png) [@carson](https://community.fibery.io/u/carson)\
**Post date:** [October 12, 2023, 4:02pm UTC](https://community.fibery.io/t/batch-operations-reference-sibling-operation-results/5286/1 "2023-10-12T16:02:21Z")

</div>

I can see that the Fibery API allows you to run batches of commands, which is really cool.

Is there some way to run a series of commands like this?:

(Pardon my psuedoJSON - I know this isn’t the correct syntax/schema for the Fibery API, but hopefully you understand the intent)

```json
[
  {
    "command": "create-entity",
    "data": {...},
    "return": "SOME_KIND_OF_REFERENCE_TO_THE_FIRST_RESULTS"
  },
  {
    "command": "update-entity",
    "target": { "fibery/id": "$SOME_KIND_OF_REFERENCE_TO_THE_FIRST_RESULTS" },
    "data": {...}
  }
]

```

I assume that you can’t, and that you can only batch operations on the database in the state it’s in before ANY of the operations are run. But I thought I’d check, because FIbery continues to pleasantly surprise me, and you never know…

---

<div class="post-metadata">

**Author:** ![Viktar\_Zhuk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/viktar_zhuk/32/1934_2.png) [@Viktar\_Zhuk](https://community.fibery.io/u/Viktar_Zhuk)\
**Post date:** [October 16, 2023, 6:24pm UTC](https://community.fibery.io/t/batch-operations-reference-sibling-operation-results/5286/2 "2023-10-16T18:24:12Z")

</div>

Hi there,  
`api/commands` indeed accepts an array of commands, however there is a catch.

- this commands will be executed sequentially
- if one command fails it won’t stop execution
- each command will run in a separate transaction

You may try `fibery.command/batch`, for example it’s used here [Fibery API](https://api.fibery.io/#single-select-field) for creating Single Select and populate it with some select-items in one batch.

To achieve your behaviour with `"SOME_KIND_OF_REFERENCE_TO_THE_FIRST_RESULTS"` we usually recommend the following approach:

- generate `fibery/id` upfront for each entity to be created. It should be [UUID version 4](https://en.wikipedia.org/wiki/Universally_unique_identifier) e.g. **crypto.randomUUID()** in nodejs.
- then use this `fibery/id` in update / delete / add-collection-item commands.

```auto
// generate uuid e.g. 5b1b06f3-07ae-42a4-b2d4-ca00fb06ea79
[
  {
    "command": "fibery.command/batch",
    "args": {
      "commands": [
        {
          "command": "fibery.entity/create",
          "args": {
             "type": "CRM/Client",
             "entity": {"fibery/id": "5b1b06f3-07ae-42a4-b2d4-ca00fb06ea79"}
          },
        },
        {
          "command": "fibery.entity/update",
          "args": {
             "type": "CRM/Client",
            "entity": {
              "fibery/id": "5b1b06f3-07ae-42a4-b2d4-ca00fb06ea79",
              // ... ("field name": "field value") pairs to update
            }
          }
        }
      ]
    },
  }
]

```

Also please mind that you can set Reference values in Entity create command, so you don’t need to split it into several commands in that case, however it is not the case for adding Entity into some other Entity collection field.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![carson](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/carson/32/7503_2.png) [@carson](https://community.fibery.io/u/carson)\
**Post date:** [October 16, 2023, 7:59pm UTC](https://community.fibery.io/t/batch-operations-reference-sibling-operation-results/5286/3 "2023-10-16T19:59:44Z")

</div>

Woah, you can generate the ID ahead of time??? That’s wonderful. Yeah, in this case, I’m trying to connect a collection reference field, but this is good to know for later.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [October 21, 2023, 5:41pm UTC](https://community.fibery.io/t/batch-operations-reference-sibling-operation-results/5286/4 "2023-10-21T17:41:57Z")

</div>

The uuid utility function may be useful for you:  
[https://the.fibery.io/@public/User\_Guide/Guide/Scripts-54/anchor=Utils-service-functions--7f5abb66-1887-40c2-a3ed-3ed22ac0292f](https://the.fibery.io/@public/User_Guide/Guide/Scripts-54/anchor=Utils-service-functions--7f5abb66-1887-40c2-a3ed-3ed22ac0292f)
