# Use updateEntity with multi-select fields

**URL:** <https://community.fibery.io/t/use-updateentity-with-multi-select-fields/3108>\
**Category:** Get Help\
**Created:** [July 24, 2022, 10:01pm UTC](https://community.fibery.io/t/use-updateentity-with-multi-select-fields/3108 "2022-07-24T22:01:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cannibalflea](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/cannibalflea/32/318_2.png) [@cannibalflea](https://community.fibery.io/u/cannibalflea)\
**Post date:** [July 24, 2022, 10:01pm UTC](https://community.fibery.io/t/use-updateentity-with-multi-select-fields/3108/1 "2022-07-24T22:01:17Z")

</div>

I was trying to find examples of how to add multiple items to multi-select fields using scripts and the updateEntity function. I was passing in the following `values` object to the function:

```auto
{
  Name: 'Test task',
  Assignee: 'bae5f000-5af9-11eb-bced-bb2f3ecffbc1',
  Status: 'Assigned',
  Priority: ['Important', 'Urgent']
}

```

Everything works fine except for the `Priority` field which is a multi-select field. When I pass the object, I get the following error:

```auto
updateEntity: Only string values are supported for enum fields

```

I tried passing the `fibery/id` values as well and got the same error.

Apologies if this is explained somewhere and I missed it.

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [July 25, 2022, 11:44am UTC](https://community.fibery.io/t/use-updateentity-with-multi-select-fields/3108/2 "2022-07-25T11:44:56Z")

</div>

Hi, @cannibalflea

Could you please give more context where are you going to use this code? Is it automations script action?

Thanks,  
Oleg

---

<div class="post-metadata">

**Author:** ![cannibalflea](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/cannibalflea/32/318_2.png) [@cannibalflea](https://community.fibery.io/u/cannibalflea)\
**Post date:** [July 31, 2022, 12:36am UTC](https://community.fibery.io/t/use-updateentity-with-multi-select-fields/3108/3 "2022-07-31T00:36:35Z")

</div>

Hi @Oleg ,

Sorry for the delay in getting back to you. Yes, I am building an automation script action. The action is triggered whenever a “Task” entity is created and it parses the name of the entity, looking for predefined tags enclosed in `[]`. So I would create an entity called:

> Complete the review of the specifications **[to** me **]** **[by** 0 aft **]** **[tags** i u **]**

The automation script would take each of the items enclosed by `[]` and using the first word, prepares an object to update the entity:

> **[to me/Contact Name]**: assigns the task to the entity’s creator (me) or a Contact entity with the given name (if multiple Contacts are found, it adds a note to the task to double check the name
> 
> **[by #days morn/aft/eod]**: assigns the deadline by setting the date to today+#days and the time based on predefined value of what morn/aft/eod means
> 
> **[tags u i]**: sets the task priority with u=urgent and i=important. none/one/all of these could be selected as `Priority` is a multi-select field

I collect the updates in the `entUpdates` object, which looks like:

```auto
{
  Name: 'Test task',
  Assignee: 'bae5f000-5af9-11eb-bced-bb2f3ecffbc1',
  Status: 'Assigned',
  Priority: ['Important', 'Urgent']
}

```

And then try to update the entity:

```auto
await fibery.updateEntity(entity.type, entity.id, entUpdates);

```

This is where I get the error.

This sounds a bit crazy but it is the best solution that I could come up with to set of the parameters for tasks without leaving the writing context.

I hope that makes sense. I can post the entire script if that is helpful.

---

<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:** [August 5, 2022, 12:19pm UTC](https://community.fibery.io/t/use-updateentity-with-multi-select-fields/3108/4 "2022-08-05T12:19:16Z")

</div>

Hi @cannibalflea  
Multi-select is coded as relation field with many-to-many semantic. Not quite sure if there is a custom logic in Script API, will ask the author. However you definitely may utilise a common API.  
So instead of Names of Priority you should use ids like one you use for Assignee, please find script example bellow.

```auto
const fibery = context.getService('fibery');

// affected entities are stored in args.currentEntities;
// to support batch actions they always come in an array
for (const entity of args.currentEntities) {
    // expansive call, avoid it if you can
    const schema = await fibery.getSchema();

    // Test/Project is a name of Project type in Test space
    // Test/Priority is a name of Priority field in Project type
    const typeFieldNames = schema.typeObjectsByName["Test/Project"].fieldObjects.map((f) => {
        return {
            name: f.name,
            uiTitle: f.title,
            fieldType: f.type,
            kind: f.kind,
        };
    })

    console.log("Project Fields", typeFieldNames);

    const multiSelectType = schema.typeObjectsByName["Test/Project"].fieldObjectsByName["Test/Priority"].type;
    console.log("multiSelectType", multiSelectType);

    const selectValues = await fibery.executeSingleCommand({
        command: "fibery.entity/query",
        args: {
            query: {
                "q/from": multiSelectType,
                "q/select": ["fibery/id", "enum/name"],
                "q/limit": 10,
            }
        }
    });

    console.log("selectValues", selectValues);

    const valuesMap = new Map( selectValues.map((x) => [x["enum/name"], x["fibery/id"]]));

    // cast to a String to make redactor happy
    const highPriorityId = String(valuesMap.get("high"));
    console.log("highPriorityId", highPriorityId);

    await fibery.addCollectionItem("Test/Project", entity["Id"], "Priority", highPriorityId);
}

```

Custom script logs (console.log) you may find in Activity tab

 ![Screenshot 2022-08-05 at 15.18.03](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/c/cc215478cafe0de5450c9d3653988e992aa535c0.png)
