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

Trying to use this and I’m getting the error message: Each param should have database.

Here is the example request I am making:

{
    command: "fibery.entity/query",
    args: {
      query: {
        "q/from": "my_space/my_db",
        "q/select": ["fibery/id", "my_space/Name"],
        "q/where": ["=", ["my_space/Name"], "$search_name"],
        "q/limit": 1,
      },
    },
    params: {
      $search_name: "John Smith",
    },
  }

In Postman:

Also paging @Oleg or @Sergey_Truhtanov :point_up_2:

Hi!
params key should be under args key.
So the structure should be following:

command:
args: {query, args}

1 Like

Is this any use?