How to get args.currentEntities of sub entities using "Id"?

I am modifying the close-task-and-all-subtasks example in order to set the state of the subtasks based on calculations.

The calculations is easy for the current entity using args.currentEntities as all the arguments of the current entity is received by the button script and available to be used in my calculations.

How do I get access to the args.currentEntities of the subtasks ?

The ...task["Subtasks"].map( (st) => {console.log(st)}) iterates the “Subtasks” and in the console log the Id and Name of every subtask is available.
How do I get all the arguments (args.currentEntities) of the specific entity using the Id available ?

My code is as follows:

const api = context.getService("fibery");

await Promise.all(args.currentEntities.map(async (e) => {
    const task = await api.getEntityById(e.type, e.id, ["Subtasks"]);
    console.log(task);
    return Promise.all([
        ...task["Subtasks"].map( (st) => {
            console.log(st);
        })
    ])
}));

Ok, I have figured it out, the following line in the code returns the value of the “Date Required” and “Effort” fields of every “subtask” of the current “task”:

const subtask = await api.getEntityById('Subtask', st.id, ['Date Required','Effort']);

The list of fields can be expanded to include all of the values of all fields of the subtask required in my calculations. The “map” method executes this for the whole array of subtasks of the subtask type.

Code in button:

const api = context.getService("fibery");

await Promise.all(args.currentEntities.map(async (e) => {
    const task = await api.getEntityById(e.type, e.id, ["Subtasks"]);
    console.log(task)

    return Promise.all([
        ...task["Subtasks"].map(async (st) => {
            const subtask = await api.getEntityById('Subtask', st.id, ['Date Required',Effort"]);
            console.log(subtask);
        }
    )])
}));
1 Like

Many thanks for sharing your results! :sparkling_heart: