Either I don't understand the question or your approach to the solution. The way I understood it, he wants to use the value returned from a table lookup (e.g. "Monkeys") as the key to look up another value (e.g. 12). I'm missing the part where I'd need to find the largest value of something.
Original Message:
Sent: 02-06-2025 19:18
From: Robert Wakefield-Carl
Subject: Using returned field from Data Table to get value of Variable
How will that find the largest value of 12 without looping through each to get squeeze it out of the collection?
------------------------------
Robert Wakefield-Carl
ttec Digital
Sr. Director - Innovation Architects
Robert.WC@ttecdigital.com
https://www.ttecDigital.com
https://RobertWC.Blogspot.com
Original Message:
Sent: 02-06-2025 16:21
From: Dave Halderman
Subject: Using returned field from Data Table to get value of Variable
To do it without the JSON, you could build the collections for animal names [Monkeys, Horses, Mice] and animal numbers [12, 4, 3], then use something like this to pull the correct value out of the list: GetAt(Flow.AnimalNumberList,FindFirst(Flow.AnimalNameList,Flow.AnimalType))
Flow.AnimalType is the value you got back from your table lookup. If Flow.AnimalType=="Monkeys", the function above returns 12.
------------------------------
Dave Halderman
Business Analyst
Original Message:
Sent: 02-05-2025 19:14
From: Robert Wakefield-Carl
Subject: Using returned field from Data Table to get value of Variable
You could consider creating collections with the names and the values and writing the values to a JSON object and then use JSONPARSE with $.items[*].value.max(). If that does not work, you could use a custom code like below to get the highest and then do a finditem on your collection and use that value with a GetAt on the names.
const jsonpath = require('jsonpath');const data = { "items": [ {"value": 10}, {"value": 20}, {"value": 30}, {"value": 40}, {"value": 50} ]};const values = jsonpath.query(data, '$.items[*].value');const maxValue = values.reduce((max, val) => Math.max(max, val), -Infinity);console.log(maxValue);
------------------------------
Robert Wakefield-Carl
ttec Digital
Sr. Director - Innovation Architects
Robert.WC@ttecdigital.com
https://www.ttecDigital.com
https://RobertWC.Blogspot.com
Original Message:
Sent: 02-05-2025 18:20
From: Peter DeMarco
Subject: Using returned field from Data Table to get value of Variable
Hello,
Is there an expression that would allow me to use the returned value of a field of a Data Table as the name of the Variable that I want to get the value of?
As an example, a flow is passed the current inventory of animals:
flow.Monkeys = 12
flow.Horses = 4
flow.Mice = 3
The Data Table itself houses these entries:
PetShopName | AnimalsNeeded |
Quite the Herd | Horses |
Best Cheese | Mice |
Barrel of Fun | Monkeys |
When a look up for Barrel of Fun is made the return to Flow.AnimalsNeeded is "Monkeys"
And ultimately, I want the value of Flow.Monkeys (or 12)
The best analogy I can think of is in Excel and the use of named ranges and the Indirect function, where the cell Monkeys has the value of 12, cell AnimalsNeeded has the value of "Monkeys", and the formula is =Indirect(AnimalsNeeded).
In the real world, we are using this to build dynamic menu prompts. And the current solution has a complex series of Switch statements that check the value returned from the Data Table, and route it to an Update Data action for each possible outcome. This can quickly become large and cumbersome.
I do understand there would be a need for error trapping if a Variable Name was entered into the Data Table that was not defined in the Flow - but first I wanted to check if this expression method even existed, as I did not see anything like it in the list (almost similar to a FindUserPrompt expression, but FindVariable or GetVariableValue)
#ArchitectureandDesign
------------------------------
Peter DeMarco
na
------------------------------