Legacy Dev Forum Posts

 View Only

Sign Up

Dynamic variables in data action

  • 1.  Dynamic variables in data action

    Posted 06-05-2025 18:44

    PriyaBBox | 2023-10-31 02:22:21 UTC | #1

    Hi everyone,

    My API request to SNOW returns an array of size 19 to 25 depending on the unique ID that I send as the input. My question is , Is there a way to dynamically create variables for each element of the result array? I will be using these variables in a script which will list these array elements as a 'dropdown' from which the agent will choose one element.

    I tried exploring velocity macros and other VTL features like #foreach (Which would be useful in my case, but found that Genesys doesnt support it from another article in the forum), $util.parse which is not supported as well (I believe so!). I tried using the response template like below, where I am first trying for one element from my result array,

    { "translationMap": { "categories": "result.[*].value", "n":"result.size()" }, "translationMapDefaults": { "categories": "[]", "n":"0" }, "successTemplate": "#if($n > 0)\n#set($category1 = $categories[0])\n#end {}" }

    It keeps failing with the error,

    1. Apply output transformation: Transform failed to process result using 'successTemplate' template due to error:'Object 'java.lang.String' does not contain method get(java.lang.Integer) at successTemplate**

    Is there any other way to do this? Please do correct my template if that will help.


    Jason_Mathison | 2023-11-02 01:35:14 UTC | #2

    Hi Priyavarshini Manohar,

    The issue is that after processing the translationMap, categories is a string that happens to have a json array in it. It is not actually a list that you can reference individual items from.

    This post gives an example of splitting a string back up into an array where you could can reference items from it https://developer.genesys.cloud/forum/t/data-table-splitting-and-random-choice/20259

    However, since the number of possible variables has a limit, this approach might actually be easier to deal with:

    {
    "translationMap": {
    "category1": "result.[0].value",
    "category2": "result.[1].value",
    "category3": "result.[2].value",
    "category4": "result.[3].value",
    <remaining categories>
    "n":"result.size()"
    },
    "translationMapDefaults": {
    "category1": "[]",
    "category2": "[]",
    "category3": "[]",
    "category4": "[]",
    <remaining categories>
    "n":"0"
    },
    "successTemplate": "#if($n > 0)\n#set($category1 = $categories[0])\n#end {}"
    }

    --Jason


    system | 2023-12-03 01:35:44 UTC | #3

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 22828