How to parse JSON object values in Business rule

Mrman
Tera Guru

Hi,

I am having following response which I need to parse and get the text in the 'value' key shown below . Please suggest . 

I have tried parse2.field47191.value but it is not working . Getting error as 'com.glide.script.RhinoEcmaError: Cannot read property "value" from undefined'

I have tried this. 

var parse2 = JSON.parse(responseBody);

var wvalue  = parse2.field12332.value 

{
"field12332":
{
"profile":"xyzrt",
"id":6,
"value":"NY-tester-704-HXQ-NY211"
},
} 

 

@Ankur Bawiskar 

13 REPLIES 13

Hi , I have tried but it was not working .

Hi @Mrman 

 

Did you get any errors?

Hi @Mrman 

 

I was able to get the results from the script that I provided earlier, refer to the screenshot below:

find_real_file.png

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Mrman,

The code provided by others and the code is the original question would work. So the problem is with something else.

var responseBody = '{"firstname":"Max","phones":[{"phonetype":{"id":"D83004","formattedvalue":"Home","value":"Home"},"entry":118,"phonenumber":"+1 720 435-0088","primary":true}],"links":[{"rel":"self","title":"The current profile being viewed.","url":"https://api.test.com"}],"field12332":{"profile":"xyzrt","id":6,"value":"NY-tester-704-HXQ-NY211"},"startdate":"2022-05-25","email":"testcand0881@tester.com","lastname":"Testmax"}';


var parse2 = JSON.parse(responseBody);
var wvalue  = parse2.field12332.value

Execution result:

*** Script: NY-tester-704-HXQ-NY211

 

The problem may be the following line in the original question.

I have tried parse2.field47191.value but it is not working .

The above sentence is using "field47191" instead of "field12332". Re-check the response body to find the actual name.