Assignments with no elements return error


I’m making a table within an Assignment to retrieve data from JSON. Elements do not always exist because of the type of product we make/store. How do I go about making my Assignment work without throwing errors?


Hi, provided you are on 6.13 or up: use FirstOrEmpty instead: FirstOrEmpty | Flow Classic Help | Flow Help

Regards, Roel

@rovech This is the error I’m getting now when using FirstOrEmpty:

{FirstOrEmpty(Eval(FirstOrEmpty(FirstOrEmpty(Eval(productAnaylsisByProductID.OK.productMetricDataList) WHERE name = ‘Titratable Acidity’).metricDataList).measurements) ORDER BY measurementDate DESC)}

Does anyone know how to handle the error above? I’m not having any luck.


You need to inspect your data. FirstOrEmpty function will return a empty record if you have an empty table input. That’s why you get that error message. The FirstOrEmpty function requires a table as input.

Nesting First functions like that isn’t very robust. If you for some reason have empty tables/arrays/lists in your productAnaylsisByProductID data, your Flow will crash.

I would advise to query and filter the data when fetched. If this isn’t possible somehow. Divide the script into steps and add error handling. This can be done in a script step to add logic to verify whether the table is empty before applying the FirstOrEmpty function. If the table is empty you can: e.g., log an error, skip the operation, or provide a default value.

To further give you guidance, please post an example of your data structure. Maybe there’s a better way filtering out the measurements.

1 Like


as Albin said, the reason FirstOrEmpty would fail is when you dont get a table back from your REST call (so flow doesnt know what is the model for the empty record to return)

The solution that comes to my mind (actually came from this Forum Any FlowScript functions to check if a Table has a specific column? - #7 by PvanderHeyden so thank you @mew :slight_smile: ) is make sure you have the record using JSON encode and then manually provide an empty record in case it doesnt exist.

So something like this:

If it is possible that one of the tables within a table is missing even when you have the name =xx then you would need to check for “meas1” also.
(Although instr-ing often in a flow against a large string may have some performance drawbacks)

Hope this helps!

testb.flow (20.6 KB)

1 Like