09-21-2022 12:43 PM
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":
}]
}
Solved! Go to Solution.
09-21-2022 01:44 PM
09-21-2022 01:06 PM
09-21-2022 01:31 PM
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?
09-21-2022 01:40 PM
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.
09-21-2022 01:44 PM
09-21-2022 02:17 PM
ah, simpler. Thank you.
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: