Button Howto: Link task to other object (relation)

Wanted a button to assign a team to a task when clicking the button. Got the following solution:

for (const entity of args.currentEntities) {

    const team = await fibery.getEntityById("Team", "4524be10-7a6a-11eb-8005-e144590b652c",["Id"]);

    // to update an entity provide an object with the new values
    
    await fibery.updateEntity(entity.type, entity.id, {
        'Team': team["id"]
    });
}

The UUID I got by scanning network traffic. Is there an easier way to determine it?

try something like this:

const fibery = context.getService('fibery');
const Anything = await fibery.executeSingleCommand({

    "command": "fibery.entity/query",
    "args": {
        "query": {
            "q/from": "Your_app_name/your_type_name",
            "q/select": [
                "fibery/id",
                "Your_app_name/Name"
            ],
            "q/where": ["=", ["Your_app_name/Name"], "$search_name"],
            "q/order-by": [
                [["Your_app_name/Name"], "q/asc"]
            ],
            "q/limit": 1
        },
        "params": {
            "$search_name": "Name_to_find"
        }
    }
});

return Anything[0]["fibery/id"])

It should return the ID of the first entity of Type ‘your-type-name’ in App ‘Your_app_name’ which has Name = “Name_to_find”.

There may be other easier ways, and apologies for any coding errors…

1 Like