Use automation step results in automation scripting

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.


2 Likes

Something like this maybe?

const entity = args.currentEntities[0];

const linkedEntities = await fibery.getEntityById(entity.type, entity.id, ['Box', 'linked Material'];

const linkedBoxes = linkedEntities['Box'].map(({ id }) => id);
[...]

See this article for a better example (if I understood your context properly).

1 Like

This may or may not work, as it seems to be indeterminate whether previous steps have truly been ā€œcompletedā€ when subsequent steps are run:

1 Like

Thanks all! I will try these suggestions and update.

2 Likes

@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.

1 Like

You’re not messing anything up. The steps[1] argument does indeed only return the triggering entity and not the entity that was linked. Sorry.

1 Like

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)

Thanks for posting this solution! I am in a similar boat today and wanting to make an edit to a task, when that task is linked to a Milestone that matches specific criteria.

The current automations editor doesn’t allow me to filter by Milestone criteria when creating an automation from the Tasks database. I can filter when creating an automation from the Milestones database, but can’t get the task that was linked (that caused the automation) in a script action, only with formulas.

@ChrisG can we turn this reply into a feature request? The added scripting here takes things from no code to yes code and I think this is a great improvement!

In the example you describe, I would imagine that the easiest workaround is a formula (in the Task db) that applies the Milestone criteria, and thus is updated when a qualifying Milestone is linked.
As it happens, we are shortly about to release a feature that will allow you to apply a filter based on a related entity’s fields, at which point the workaround will no longer be needed.

1 Like

I am hoping so hard that Fibery will invest more time and effort in the automations & rules product area. I think it might be one of if not the biggest weakness of Fibery given the importance it has in this type of product.

We’ve been building automations and back-end logic in low code and no code platforms for multiple years in multiple platforms (Xano, Pipedream, Airtable, Zapier…) but we still can’t figure out the way to create automations efficiently in Fibery.

The fact of the matter is we pretty much always end up trying to fit everything in a script because the no code components are very limited. But then the Fibery Script API is so complex for what is needed, there’s always a little something that breaks the whole thing and ultimately we’re forced to move onto something else.

We had hopes with Fibery AI, but even it cannot figure out the most basic things. Other coding LLMs can’t either.

Can someone from the Fibery team inject some hope here?? :slight_smile:

Oh god, I just found this thread. That might have provided me with the hope I needed.

I am hoping so hard that Fibery will invest more time and effort in the automations & rules product area. I think it might be one of if not the biggest weakness of Fibery given the importance it has in this type of product.

@gb_carbone I was feeling exactly the same way, Fibery automation rules are very powerful but somewhat inaccessible to users that do not know how to code or use the Fibery API. So I decided to build an integration for Fibery called Fiberflow, which addresses these issues by providing a no-code editor for building advanced automations. For example, there is already an action for conditional logic (if-then-else), which helps quite a bit building automations. You can check out a simple automation using the conditional action, the Public Roadmap or submit suggestions for upcoming features :slight_smile:

1 Like

I can’t see anything interesting at that link:

@Matt_Blais unfortunate timing, I just deployed after a large refactor and broke a couple of things including the share functionality. Now It should work :slight_smile:

1 Like