Check if key/value exists on ANY returned output

Hi guys,

I need to check if a value exists on any of the outputs returned by a query, and if it exists set a variable valus as one number, otherwise set it as another number.

For a property management company I am querying all work orders that have ever been created for a building. If there is no previous WO with a category of “Lawn Care” ever created, then the lawn care price would be X as it is a “First Cut” (higher price), otherwise it would be Y.

I am able to get a list of WOs for the buildings I am interested in via an API which returns individual operations per building each containing a single bundle with a number of arrays containing the WO information.

Here’s the output from one of the operations showing a number of WOs:

…and for this specific property, there was a previous WO created with a category as Lawn Care (in fact, there are two).

Somehow I need to go through all the WOs for each building, and if any of them contain a category of Lawn Care then set a variable amount for example 10, otherwise set the value to be 20 (for that building).

Please find attached an output of the initial API query for one of the operation results in case this helps!
output.json (95.0 KB)

Regards,
Dennis

Hello!

Try this formula, mapping the relevant output: {{if(length(map(1.data; "id"; "category"; "Lawn Care")) != 0; 10; 20)}}

It generates a new array that contains all id where category=Lawn Care, then it calculates its length. If 0, it means nothing was found => 20, if more than 0, at least one found => 10

Benjamin

3 Likes