Is it possible to use/call automation step results in scripts?
For example, I have an automation script the triggers when a Material entity is linked to a Box entity. If I create the automation in the Box DB I can get the Box entity info when I use args.currentEntities, but not the Material info. I have the opposite problem if I make the automation in the Materials DB. As a Box entity has many Material entities, I either need to get the Material that triggered the entity or filter all connected entities by most recently added. I’ve attempted filtering with GraphQL queries but haven’t been successful so far. I’ve attached images to show the automation trigger and the entity info.
@Chr1sG Thanks for the info! I’m still not sure that I’m able to get the correct entity info from the first step. When I log args.steps[1] it only returns the entity that the automation has triggered for, not the linked entity. Apologies if I’m just totally messing up the syntax.
Alright, after quite a bit of messing around I think I found an ok way to do this. It seems like grabbing the first item in the array when sorting by modification date should always get you the most recently linked entity and therefore the entity that triggered the automation. I would be curious if there is a better way to do this, but this works ok for my purposes. As usual I SUPER appreciate everyone’s help!
const fibery = context.getService('fibery')
//Insert the name of your space below
const SPACE_NAME = ''
const entity = args.currentEntities[0]
//Modify the query for you scenario, the database I'm querying from is called 'Box' and the linked database is 'Material'
const query = `{findBoxes(id: {is: "${entity.id}"}) {materials(orderBy: {modificationDate: DESC}) {id, name, modificationDate}}}`
const result = await fibery.graphql(SPACE_NAME, query)
const firstMaterialId = result.data.findBoxes[0].materials[0].id;
console.log(firstMaterialId);
console.log(result)