How to add two values to successTemplate output

I have a observation query action, and I want to get a total amount for two different results, how do I achive this?

{
  "translationMap": {
    "queueLengthVoice": "$.results[?(@.group.mediaType==\"voice\")].data[?(@.metric==\"oWaiting\")].stats.count",
    "queueLengthCallback": "$.results[?(@.group.mediaType==\"callback\")].data[?(@.metric==\"oWaiting\")].stats.count",
    "agentsOnQueueInteracting": "$.results[?(@.group.queueId)].data[?(@.metric==\"oOnQueueUsers\"&&@.qualifier==\"INTERACTING\")].stats.count",
    "agentsOnQueueIdle": "$.results[?(@.group.queueId)].data[?(@.metric==\"oOnQueueUsers\"&&@.qualifier==\"IDLE\")].stats.count",
    "totalQueue": ??
  },
  "translationMapDefaults": {},
  "successTemplate": "{
     \"agentsOnQueueIdle\": ${successTemplateUtils.firstFromArray(\"${agentsOnQueueIdle}\", \"0\")}, 
      \"agentsOnQueueInteracting\": ${successTemplateUtils.firstFromArray(\"${agentsOnQueueInteracting}\", \"0\")}, 
      \"queueLengthVoice\": ${successTemplateUtils.firstFromArray(\"${queueLengthVoice}\", \"0\")}, 
      \"queueLengthCallback\": ${successTemplateUtils.firstFromArray(\"${queueLengthCallback}\", \"0\")}, 
      \"TotalQueue\": ${successTemplateUtils.firstFromArray(\"${totalQueue}\", \"0\")}}"
}

If you look at the translationMap, I want the values for "queueLenghtVoice" and "queueLenghtCallback" to be added together in the value "totalQueue".

Ive tried different ways, but I couldn't figure out using Velocity macros with the math prefix how to achive this. Appreciate all insights you could share, thanks.

Hello,

This should work.
I am using 2 temporary variables (nbVoice, nbCallback) to gather the nb of calls and the nb of callbacks so I can then add them with math.add.

{
  "translationMap": {
    "queueLengthVoice": "$.results[?(@.group.mediaType==\"voice\")].data[?(@.metric==\"oWaiting\")].stats.count",
    "queueLengthCallback": "$.results[?(@.group.mediaType==\"callback\")].data[?(@.metric==\"oWaiting\")].stats.count",
    "agentsOnQueueInteracting": "$.results[?(@.group.queueId)].data[?(@.metric==\"oOnQueueUsers\"&&@.qualifier==\"INTERACTING\")].stats.count",
    "agentsOnQueueIdle": "$.results[?(@.group.queueId)].data[?(@.metric==\"oOnQueueUsers\"&&@.qualifier==\"IDLE\")].stats.count",
    "totalQueue": ??
  },
  "translationMapDefaults": {},
  "successTemplate": "#set ($nbVoice = ${successTemplateUtils.firstFromArray(\"${queueLengthVoice}\", \"0\")})#set ($nbCallback = ${successTemplateUtils.firstFromArray(\"${queueLengthCallback}\", \"0\")}) { \"agentsOnQueueIdle\": ${successTemplateUtils.firstFromArray(\"${agentsOnQueueIdle}\", \"0\")}, \"agentsOnQueueInteracting\": ${successTemplateUtils.firstFromArray(\"${agentsOnQueueInteracting}\", \"0\")}, \"queueLengthVoice\": ${nbVoice}, \"queueLengthCallback\": ${nbCallback}, \"TotalQueue\": $math.add(${nbVoice},${nbCallback})}}"
}

Regards,

Thank you very much, this helped!
kind regards!

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