[SOLVED] API entity update status

Hello, I fell a little lost in trying to change the workflow status of an entity.
The workflow is the “default” fibery workflow with Open, In Progress, Done.

With the query below I changed the Name [enum/name] of the whole
workflow state and not the state of the entity.

db_sync_cmd = [
‘[{’,
‘“command”:“fibery.entity/update”,’,
‘“args”:{’,
‘“type”:“workflow/state_Projekt Planung/Task”,’,
‘“entity”:{’,
f’“fibery/id”:"{fib_task[“workflow/state”][“fibery/id”]}",’,
f’“enum/name”:“In Progress”’,
‘}’,
‘}’,
‘}]’,
]

fib_task[“workflow/state”][“fibery/id”] =
ID of the workflow status I got from the query I do initially to get entity information
{“workflow/state”: [“fibery/id”, “enum/name”]}

Instead of updating the workflow entity, you should be updating the workflow field for the entity whose status you wish to change.

Something like this:

await fibery.entity.updateBatch([
  {
    'type': 'Projekt Planung/Task',
    'entity': {
      'fibery/id': '20f9b920-9752-11e9-81b9-4363f716f666',
      'workflow/state': { 'fibery/id': 'd328b7b0-97fa-11e9-81b9-4363f716f666' }
    }
  }
]);

You’ll need to know the IDs of the entity and the In Progress state option

Thank you very much for the fast and helpful answer!!!

The ID for each state will be them same for all entities I assume?
So one ID for Done, one for In Progress…

So I just need to get them once

Yes, correct

Your the best!!! :slight_smile:
Thanks

1 Like

@Chr1sG - can I ask - what is the name of the workflow entity and what is its structure? I assume the only way to obtain this is in js by reading the workflow entity and building an array …

Workflow is itself a database, but a ‘hidden’ one.
It has fields like any other db (Name, Creation Date etc.) and has a relation to its owning type.
In the schema, the name of the workflow type is typically something like this:
workflow/state_SpaceName/OwningType
The workflow options are entities in this database, so you can query them just like any other entity in the workspace.

Not sure what the ‘this’ you want to obtain is? If you want to read the value of state, it is available when you read the entity, e.g. if you execute this:

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

for (const entity of args.currentEntities) {
    console.log(entity);
}

the output might look like this:

{
  'Created By': { Name: 'chris', Id: 'e6e65d48-ed1d-405e-ad2f-6493278c39b7' },
  'Public Id': '1',
  Id: '73db52b9-7a34-4deb-8078-f92ebc4efbf1',
  'Creation Date': '2024-03-29T11:47:14.635Z',
  'Modification Date': '2024-04-17T06:14:28.699Z',
  Rank: 8672589213253628,
  Name: 'Do this',
  State: { Id: 'be143480-fc81-11ee-8995-d94ed8550e07', Name: 'To Do' },
  Type: 'Project/Task'
}

If you need to know all possible values, then the easiest way to do it is to write a graphql query.