- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 09:47 PM
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
Solved! Go to Solution.
- Labels:
-
flow designer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 10:02 PM
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
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 09:57 PM
Hi,
it would be nice if you share the complete json string
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 10:02 PM
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
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2022 06:32 AM
Thank you it worked and solved my problem.