cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5314
Views
15
Helpful
52
Replies

JSON in UCCX Script

Hi Team,

 

Can you guide me how to create a JSON in UCCX script.

 

Regards,

 

Jijesh

52 Replies 52

You need this.

Snag_1a25a63.pngI already have shared a screenshot with this. Do you not read what is shared with you?



Response Signature


I have updated the script and run the debug. Now I am getting the  below results

Jijesh_0-1685544707008.png

Status Code below

Jijesh_1-1685544999536.png

Below variables which I created for this script

 

Jijesh_2-1685545174857.png

 

 

 

 

So what is your issue? The JSON doc is from what I can tell populated with the response that you get from the Rest call. If it is not returning what you expect you're doing something wrong in the Rest step. It could be as simple as your using the wrong request URL.



Response Signature


Let me check the Url and retest it

 

 

If I run this in our system and do the query we have defined and the resulting output that our ServiceNow platform has we get this result.

Content of the string with the response.

image.png

Content of the JSON document.

image.png

By this as what you see in your response is only U"{\"result\":[]}, so that's why you only see that in the JSON doc. What have you defined as the expected response from ServiceNow when you do the REST call? I know our SN admins defined what to include in the response.



Response Signature


@Roger Kallberg 

sorry for the delayed response.

I have added the url parameters in Rest Call and created the JSON document ,responses. 

I am getting the JSON response please see below.

U"{\"result\":[{\"user_name\":\"200065\",\"u_empgrade\":\"C2\",\"vip\":\"true\"}]}"

I tried to match vip value to route the calls nothing worked. Kindly suggest.

 

 

 

 

 

If you look at the picture I shared earlier of our script you should be able to see how to do that without too much effort. You’ll need read it as “result.vip” from the JSON document based on your output. This would give you the value “true” based on what you shared.



Response Signature


I have created the result and response string. Unfortunately getting the null value.

 

Please share a screenshot of the read JSON step. By your description it sounds like you don’t do the read from the JSON document right or maybe not at all.

This part in my previous response is what you should be looking at.

IMG_4299.jpeg

The variable that you store the state of vip once you read that from the JSON document should be a boolean as it holds true or false values.



Response Signature


 

 Below the screen short

jijeshkt_1-1685863435837.png

and I created the string value "result[0].vip" to match the result.

Let me create the boolan variable and try it.

 

 

From what I can see in your picture you are not doing the get JSON steps correctly.

You need to query the values that are in the result branch, see it like a path statement. For example for VIP you put this in “result.vip” verbatim, the path of this would be result and under it there is a value named vip that contains true. Then you store that in a variable that is of the type boolean. The variable type should be matched to fit the type of data of what you read from the JSON document.



Response Signature


I have created 2 string . Details below

1.

jijeshkt_2-1685869681411.png

2

jijeshkt_3-1685869768003.png

below variables are updated in the JSON properties.

jijeshkt_4-1685869862775.png

below responses are coming from the results.

U"{\"result\":[{\"user_name\":\"11234567\",\"u_empgrade\":\"C2\",\"vip\":\"true\"}]}"

and I am not getting any response value

 

You don’t need the first variable, put the value from that directly in the JSON path in the get JSON document step and your second variable should be of the type Boolean. I have no idea if this would make any difference. You keep referring to the result from the REST lookup, have you put that into the JSON document and if so what is the content of it?



Response Signature


Can you give a Rest look up scren shot.

I took you result from the REST call and created this simple script to get the value that you have asked about.

Snag_278167.png

There are a few things with your result from the REST call that makes it not work with what I suggested.

  1. Your result is in-between angle brackets and that makes it an array in JSON
  2. Your vip value is formatted as a string as it is in-between double quotes

In my script that tried to attach, but I just get "Sorry, unable to complete the action you requested." I added two set steps that does this.

  1. First one removes the angle brackets from the result string
  2. Second one sets the boVIP boolean variable based on the strVIP string variable

There are for sure cleaner ways to do this, but I’m not that great with the expression language and I’m for sure not a Java programmer. So I did it the simplest way.



Response Signature