Dynamic variables in data action

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,
10. 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.

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

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

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