Genesys Cloud - Main

 View Only

Discussion Thread View
  • 1.  Using returned field from Data Table to get value of Variable

    Posted 02-05-2025 18:20

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


  • 2.  RE: Using returned field from Data Table to get value of Variable
    Best Answer

    Posted 02-05-2025 19:14

    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); // Output: 50


    ------------------------------
    Robert Wakefield-Carl
    ttec Digital
    Sr. Director - Innovation Architects
    Robert.WC@ttecdigital.com
    https://www.ttecDigital.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 3.  RE: Using returned field from Data Table to get value of Variable

    Posted 02-06-2025 16:22

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



  • 4.  RE: Using returned field from Data Table to get value of Variable

    Posted 02-06-2025 19:19

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



  • 5.  RE: Using returned field from Data Table to get value of Variable

    Posted 02-07-2025 09:30

    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.



    ------------------------------
    Dave Halderman
    Business Analyst
    ------------------------------



  • 6.  RE: Using returned field from Data Table to get value of Variable

    Posted 02-06-2025 19:59

    Thank you for the quick response.  I'm realizing now that in my attempt to simplify my example I removed some necessary context for how the data is gathered and being used.

    As I mentioned, we are building dynamic menu prompts based on information pulled from a Data Table, but that is incomplete.

    The full workflow is like this

    1. customer enters their information as they navigate the menu.
    2. that information is used for an API call into our CRM to return data on an active claim.
    3. That data follows logic checks to select the needed prompt.  (i.e. Appointment Scheduled)
    4. The needed prompt is looked up in the Data Table.
      1. The data table includes a mix of Prompt Names and Variable Names that need to be constructed into the Final Prompt.
        1. PromptName1: Appointment_pt1
        2. VariableName1: MonkeyType
        3. PromptName2: Appointment_pt2
        4. VariableName2: AppointmentDate
        5. PromptName3: Appointment_p3
        6.  VariableName3: OfficePhone
        7. PromptName4: RepeatMenu 
      2. The Prompt Names and Variable Names can differ from prompt to prompt (i.e. Item, Service Date, Tech's Name/Phone Number, etc.)
    5. The results from that look up are used to play a sequence of pre-recorded prompts and TTS of the contents of the Variables.

    A final prompt might look like this (variable values in bold):

    Our records indicate that the checkup appointment for your Capuchin is scheduled for February 10th.  If you are unable to make this appointment, please contact the office at 888-555-1212.  To hear this message again, press 1. 

    The original solution involves a lot a Switch/Decision branches and multiple Play Audio actions - and the final Menu Action does not include the entire prompt.  It's not pretty, but it works. (side effect: the built-in repeat menu counter would not play the entire message, only the tail end)

    I am looking to streamline and leverage the TTS to build out a String that could be used in the Menu so it can be repeated properly, and was thinking that a Variable reference as I was trying to describe above could be cleaner than calling a multi-layered Switch statement that has a branch for each possible variable name.

    Hoping something like that exists.



    ------------------------------
    Peter DeMarco
    na
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources