Scripts: How to update an entity's fields?

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.

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 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.

1 Like

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.

1 Like

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

Thanks - that’s what I was looking for:

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