Show array data in Scripter

Hello,

I have created a Data Action to retrieve the OnQueue users for a Queue.
When running the DA I see the results as shown below:

This seems to be working fine, however when I use the DA in a script action to get the values I have to use a List Variable to write the output in. But nothing seems to be written in the List Variables when running the Custom Action.

Idealy I would like to have the total of the Idle and Interacting users as 1 integer in Scripter, not sure if this is possible. Otherwise I would like to see the retrieved data so I can make decisions based on the data.

I think I am missing something here, and I have searched the documentation and this forum but was not able to find a solution. If anyone has an idea that would be great!

Thx!

Hi Rob,

Could you post an export of your data action, and the output of the execution step in test mode? Feel free to redact anything if needed, just keep the shape of the data the same.

--Jason

Hi Jason,

I attached an export of the Data Action

getOnQueueAgentsv2.custom.json (1.9 KB)

In Execution mode (test) I get this back:

{
"results": [
{
"group": {
"queueId": "3c534f1e-b04c-4ce4-8a1f-bdf10a7ddc62"
},
"data": [
{
"metric": "oOnQueueUsers",
"qualifier": "INTERACTING",
"stats": {
"count": 1
}
},
{
"metric": "oOnQueueUsers",
"qualifier": "IDLE",
"stats": {
"count": 1
}
}
]
}
]
}

BR,
Rob

Hey Rob,

The cause of your pain was that in your transformation map you have lines like this:
"IDLE": "$.results[0].data[?(@.qualifier=='IDLE')].stats.count",

While that is the correct way to get the value, because it involves a filter like this [?(@.qualifier=='IDLE')] it is returning an array of values since there is no way ahead of time to know how many values it will match. We created the $successTemplateUtils.firstFromArray macro to help you out with situations like this. I also had to force velocity to treat the counts as numbers for the math operation to work. Finally, you will need to update your output contract to be numbers instead of arrays of numbers.

This returns IDLE, INTERACTING, and TOTAL agents:

"successTemplate": "#set ($idleAgents = $math.toInteger(${successTemplateUtils.firstFromArray(\"${IDLE}\", \"0\")})) #set ($interactingAgents = $math.toInteger(${successTemplateUtils.firstFromArray(\"${INTERACTING}\", \"0\")})) #set ($totalAgents = $idleAgents + $interactingAgents) {\"IDLE\": $idleAgents, \"INTERACTING\": $interactingAgents, \"TOTAL\": $totalAgents}"

--Jason

1 Like

Hi Jason,

Thanks for the assistance, it works like a charm now. Have a great weekend!
BR,
Rob

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