# Scripts: How to update an entity's fields?

**URL:** <https://community.fibery.io/t/scripts-how-to-update-an-entitys-fields/2112>\
**Category:** Get Help\
**Created:** [October 7, 2021, 5:31pm UTC](https://community.fibery.io/t/scripts-how-to-update-an-entitys-fields/2112 "2021-10-07T17:31:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [October 7, 2021, 5:31pm UTC](https://community.fibery.io/t/scripts-how-to-update-an-entitys-fields/2112/1 "2021-10-07T17:31:11Z")

</div>

I did not find an example for how to update a specific field in a specific entity in Button/Action scripts.

Is there a fibery.apiFunction for this, or do we need to use `fibery.executeSingleCommand / POST` ?

Actually, what I need to do is update a “to-one” relation field. So that could mean removing the existing linked entity (if any), and then link a new entity.

---

<div class="post-metadata">

**Author:** ![rothnic](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/rothnic/32/1850_2.png) [@rothnic](https://community.fibery.io/u/rothnic)\
**Post date:** [October 7, 2021, 7:11pm UTC](https://community.fibery.io/t/scripts-how-to-update-an-entitys-fields/2112/2 "2021-10-07T19:11:17Z")

</div>

If I’m understanding correctly, I believe in this case you’d just set the field name to the entity id. So, if you had a Story-\>(1) Project relationship. To change the project the Story is assigned to, you’d just overwrite the Story’s “Project” attribute with the id of the project you want to change the relationship to.

There is an [example script](https://gitlab.com/fibery-community/action-buttons/-/blob/master/waterfall-planner/start-stage.js) where they are creating entities and assigning entity ids. Assigning a new relationship is the same as overwriting one.

If the relationship is a collection, there is a specific method `fibery.addCollectionItem` and `fibery.removeCollectionItem` available.

---

<div class="post-metadata">

**Author:** ![rothnic](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/rothnic/32/1850_2.png) [@rothnic](https://community.fibery.io/u/rothnic)\
**Post date:** [October 7, 2021, 7:15pm UTC](https://community.fibery.io/t/scripts-how-to-update-an-entitys-fields/2112/3 "2021-10-07T19:15:47Z")

</div>

Also, if you don’t have it, the methods available for rule scripts are the same as what is called out as supported for [action buttons in the API docs](https://api.fibery.io/#script).

---

<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 7, 2021, 8:35pm UTC](https://community.fibery.io/t/scripts-how-to-update-an-entitys-fields/2112/4 "2021-10-07T20:35:51Z")

</div>

> [@Matt\_Blais](#):
>
> update a specific field in a specific entity in Button/Action scripts

@rothnic is basically right, unless you mean updating an entity that is **not** the one that triggered the automation (or had a button pressed)?

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [October 7, 2021, 9:56pm UTC](https://community.fibery.io/t/scripts-how-to-update-an-entitys-fields/2112/5 "2021-10-07T21:56:12Z")

</div>

Thanks - that’s what I was looking for:

`fibery.updateEntity(type: string, id: string, values: object): Promise<void>`
