Flow Designer Response Body

Michael48
Tera Contributor

I need help get the value of two fields ball and cat from the flow designer. but the script i currently have is not populating the field. 

 

This is a sample of the Response body below

{
   "key": "xxxxx",
   "keyName": "xxxx",
   "operator": "equals",
   "resultSet": [
      {
         "field_A": "watch",
         "field_b": "green", 
"
field_C": "white",
"
field_d": "German",
}
],
"rowCount": x,
"rowLimit": "xxxxx",
"tableName": "xxxx"
}



Below is the Script am using in the script step to extract the fields b and C but its not working

(
function execute(inputs, outputs)
{
if (inputs.status_code == '200')
{
// Create an object from the JSON response
var responseObject = JSON.parse(inputs.response_body);

//Write values from the object to the output variables
outputs.environmental_category = responseObject.resultSet.field_A;
outputs.collector_date = responseObject.reultSet.
field_b
; 
}
}
)(inputs, outputs);



PLEASE WHAT AM I DOING WRONG AND PLEASE CAN YOU HELP ADJUST MY SCRIPT

 

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

Please try below:

(
 function execute(inputs, outputs) 
 {
 if (inputs.status_code == '200')
 {
 // Create an object from the JSON response
 var responseObject = JSON.parse(inputs.response_body);
 
 //Write values from the object to the output variables
 outputs.environmental_category = responseObject.resultSet[0]["field_A"];
 outputs.collector_date = responseObject.resultSet[0]["field_b"];
; 
 }
 }
)(inputs, outputs);

 

As resultSet is an Array you need to access it with index resultSet[0]

 

Thanks.
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it would be nice if you share the complete json string

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Anil Lande
Kilo Patron

Hi,

Please try below:

(
 function execute(inputs, outputs) 
 {
 if (inputs.status_code == '200')
 {
 // Create an object from the JSON response
 var responseObject = JSON.parse(inputs.response_body);
 
 //Write values from the object to the output variables
 outputs.environmental_category = responseObject.resultSet[0]["field_A"];
 outputs.collector_date = responseObject.resultSet[0]["field_b"];
; 
 }
 }
)(inputs, outputs);

 

As resultSet is an Array you need to access it with index resultSet[0]

 

Thanks.
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thank you it worked and solved my problem.