" /> use a multi entry JSON array to populate variables in Composer - Genesys CTI User Forum

Author Topic: use a multi entry JSON array to populate variables in Composer  (Read 2333 times)

Offline aklinbail

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Advertisement
Hi,

My company has developed a web front-end that is intended to be used instead of GAX for external customers.
This is to provide them with limited control of GVP IVR's.  (no one like the GAX interface :( )

They are providing the data in a JSON array that looks like this.
[{"node_id":"1","status":"false","message_id":"0","next_action_id":"NULL","audio_file_path":null},{"node_id":"2","status":"false","message_id":"0","next_action_id":"NULL","audio_file_path":null},{"node_id":"3","status":"true","message_id":"1","next_action_id":"test_action","audio_file_path":"http:\/\/mnlstaging.ad.busapp\/segueapps\/ivr\/uploads\/audio-messages\/Test Message(2-23-2017).mp3"}];

I am retrieving this from a webrequest block. and assigning that to a variable varWSreturn

I am trying to populate some variables which are then used to drive various decision points and pick up audio where required.
The variables are defined as user variables .. e.g. varStatus1, varStatus2, varStatus3, varAction1, varAction2,varAction3 varAudio1,varAudio2,varAudio3 e.t.c.

Here is what I have tried as Javascript

var obj = varWSreturn;

var vstatus='varStatus';
var vaction='varAction';
var vaudio='varAudio';

for (var key in obj) {
if (obj.hasOwnProperty(key)) {
vstatus.concat(obj[key].node_id)=obj[key].status;
vaction.concat(obj[key].node_id)=obj[key].next_action_id;
vaudio.concat(obj[key].node_id)=obj[key].audio_file_path;

So I am expecting this to loop through the string and populate the variables as I have explained above..
However, it is returning nothing..

I'm not hugely versed in javascript, other than various snippets in composer... So please excuse me if I've completely screwed this..

Any suggestions will be much appreciated (even if it means using the loop block and completely different method.

Regards

Allan






















« Last Edit: March 16, 2017, 07:06:56 AM by aklinbail »

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7641
  • Karma: 56330
Re: use a multi entry JSON array to populate variables in Composer
« Reply #1 on: March 16, 2017, 11:56:15 AM »
Obj[0] wouldn't be?

Enviado de meu E6633 usando Tapatalk


Offline aklinbail

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: use a multi entry JSON array to populate variables in Composer
« Reply #2 on: March 17, 2017, 03:29:28 AM »
Yes that worked.

It's not exactly what I wanted, as it means I have to specifically code in each variable e.g.

for (var key in obj) {
    if (obj.hasOwnProperty(key)) {
    varAction1=obj[0].next_action_id;
    varAction2=obj[1].next_action_id;
}
}
I was trying to do this dynamically, so that I can create a subroutine that works for any IVR no matter how few or many options it has..

This will do for now, but if anyone can suggest how to make this completely dynamic it would be very much appreciated.

Regards

Allan

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7641
  • Karma: 56330
Re: use a multi entry JSON array to populate variables in Composer
« Reply #3 on: March 17, 2017, 04:46:17 AM »
Instead of actionx do an array of actions. Then you go through it doing a simple for 0 to var.length

Easier.

You need a better design at your system idea. Some software architect can help you

Enviado de meu E6633 usando Tapatalk


Offline aklinbail

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: use a multi entry JSON array to populate variables in Composer
« Reply #4 on: March 19, 2017, 11:17:21 PM »
Sorry, I don't actually understand what you mean.

Offline aklinbail

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: use a multi entry JSON array to populate variables in Composer
« Reply #5 on: March 19, 2017, 11:50:33 PM »
The architecture for variable number of entries in the JSON string is due to the fact this system is required by a number of different external clients with various needs.