I was looking at the original post you referred to and was playing around with something similar. I thought I would upload some sample code that shows how to get properties (incl collections) of related types using the action button.
In this case, I have a Project with multiple related Tasks. When the button is pressed (for any Task) the code finds the parent Project and then finds all Tasks associated with this Project and iterates through renaming them.
If I’ve understood your problem, it would seem to be possible to adapt the code to get other properties of the parent entity as you need.
const api = context.getService("fibery");
for (const e of args.currentEntities) {
const task = await api.getEntityById(e.type, e.id, ["Project"])
const projectID = task["Project"].id
const project = await api.getEntityById("Project", projectID, ["Name","Tasks"])
const projName = project["Name"]
const taskCollection = project["Tasks"].map(u => u.id)
var i = 0
for (const task of taskCollection) {
i = i + 1
const taskObj = await api.getEntityById("Task", task, ["Property"])
const newName = projName + " " + i + " - " + taskObj["Property"]
await api.updateEntity("Task", task, { "Name": newName })
}
}
FYI, I’m not a coder, so I’m sure it could be done more nicely :-/
Using getEntityById unfortunately only gets the ID of collections (like workflow state). In that case I would then have to at least get each uniquely appearing state ID to read its data that I can use for further logic.
Not sure how fast that would be compared to a single request that is able to get all data. Depending on how the backend logic works and other conditions, either could be faster and more efficient than the other
By the way for the case above (load nested entities with fields), we introduced getEntitiesByIds method. So you first load entities of level 1, and then load entities of level 2 with required fields, performing only 1 query. So this still be good in terms of efficiency.
But definitely commands api will be still faster, as only one query is required. But as commands api is a bit cubersome, we introduced this simplified shortcuts methods in button api.