Action Buttons Q&A

I think it’s a nice idea - I too am an Action Button fan but with no JS experience or training, relying on trial&error, guesswork and determination. I have become better over time, but I also know that @Haslien and @Sergey_Truhtanov are pretty helpful if you get stuck.

To begin with, I’m pretty sure that I can answer Q1:
The entity’s state field is pretty much the same as any other single-select field, which means that behind the scenes, it is a type of its own, and you have to treat it accordingly.
For example, the following code will get you the state of an entity:

for (const entity of args.currentEntities) {
    const item = await fibery.getEntityById(entity.type, entity.id, ["State"]);
    const state = item["State"];
    return state["Name"];
}

Also, I will add that the (totally undocumented) fibery.executeSingleCommand is a brilliant way to achieve lots of stuff that would otherwise become a bit cumbersome using just the standard action button methods.
Have a look here: Command methods for button, and/or token availability in context
This method might actually help with Q3. I don’t think there is any way to get all fields without knowing what fields you’re asking for. But you could use the "command": "fibery.schema/query" to get the full structure of all your types, and from there, you could iterate through reading all the fields of a given entity’s type.

Using fibery.executeSingleCommand does require getting to grips with objects, but it’s actually not as hard as you might think, and I got a useful tip for a good JS learning resource: Extracting useful info from <del>JSON</del> JS object
Plus, the documentation for the general API commands is pretty easy to follow.

As for Q2, yes it is definitely possible:
await fibery.updateEntity(entity.type, entity.id, { "Name": "Hi 👍" });
:blush:

1 Like