cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
531
Views
10
Helpful
5
Replies

Get Array Count from Web Svc Call in Call Studio

SANJ21
Level 1
Level 1

Running CVP v12.6. I am using the Rest_Client element in CS to do a web service call and am getting a JSON array response back. I have a requirement to handle calls based on the array counts. Within an Action Element-Set Value element, I tried doing a JSON.parse and using the length() to get the count but am either getting an error or null value depending on the iterations I tried. Can someone provide the right syntax if this can be done? The JSON data I get back is in this format below:

{"Results":[
   {"Name":
    "Address":
    "Phone":
   }
   {"Name":
    "Address":
    "Phone":
   }]
}

1 Accepted Solution

Accepted Solutions

No. You ONLY need to do this one line - it'll return the length into
your localVariable:

JSON.parse({Data.Element.restZipcodeLookup.response_body}).Results.length;



View solution in original post

5 Replies 5

janinegraves
Spotlight
Spotlight
Use this: JSON.parse({Data.Element.Rest01.response_body}).Results.length;



Thanks Janine. I have the following in an Action Element - Set Value:

var val = {Data.Element.restZipcodeLookup.response_body};

var path = JSON.parse({Data.Element.restZipcodeLookup.response_body}).Results.length;

JSONPathUtil.eval(val,path);

 

However, looking at the logs, I am seeing the value as null. I also have a Decision element after this to do other things if the count is more than the current counter but it's failing there as well...probably because I'm not getting a valid value. Any ideas?

NM.

This looks like how it should be:

var val = JSON.parse({Data.Element.restZipcodeLookup.response_body}).Results.length;

var path = "$";

JSONPathUtil.eval(val,path);

 

Just need to fine tune my app to handle the result.

No. You ONLY need to do this one line - it'll return the length into
your localVariable:

JSON.parse({Data.Element.restZipcodeLookup.response_body}).Results.length;



ah, simpler. Thank you.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: