- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 05:10 PM
I have a REST message. I'm getting the data back in the response (see below). But when I try to parse the fields out so I can update the fields on my form, I get undefined.
What am I missing?
var response = restMessage.execute();
gs.log(response.getBody());
//{"result":[{"u_segment":"Regional","u_account_owner":"Denise Bond","name":"123 MONEY LLC","u_region":"NE"}]}
var str = response.getBody();
var parser = new JSONParser();
//var parsedResponse = response.parser(str);
var parsedResponse = parser.parse(str);
gs.log(parsedResponse.result.name);
//Set values returned to incident form
current.u_account_name = parsedResponse.result.name;
current.u_account_owner = parsedResponse.result.u_account_owner;
current.u_region = parsedResponse.result.u_region;
current.u_segment = parsedResponse.result.u_segment;
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2017 04:38 AM
Hi Christina,
Following script will give you the desired values:
You missed the array of object. the values are present in result[0]
var response = restMessage.execute();
var str = response.getBody();
var parser = new JSONParser();
var parsedData = parser.parse(str);
current.u_account_name = parsedData.result[0].name;
current.u_account_owner = parsedData.result[0].u_account_owner;
current.u_region = parsedData.result[0].u_region;
current.u_segment = parsedData.result[0].u_segment;
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
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
‎08-08-2017 07:34 AM
Turns out the variable substitution didn't work for the org number.
I created an outbound rest message instead of having it all in the business rule.
If via the business rule I pass the org # explicitly.. ie B222221234, it works. But passing in the field name or variable it does not pass the value and I get no results.
What am I missing for the variable substitution?
TIA
Rest message
Get method
Business Rule
var org = current.u_parent_org_id;
gs.addInfoMessage('Org' + org);
if (org != '') {
var restMessage = new sn_ws.RESTMessageV2('Get Org Info', 'get');
restMessage.setBasicAuth('xxxx','xxx');
restMessage.setStringParameter("org", current.u_parent_org_id);
var response = restMessage.execute();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2017 07:44 AM
Hi Christina,
Can you check whether current.u_parent_org_id has any value. Also check whether you have created variable substitution for the GET function in the related list.
Try adding log statements.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
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
‎08-08-2017 07:53 AM
I was missing the variable substitution for the get method of the REST message.
Thank you for all your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2017 07:56 AM
Good catch.
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-06-2020 04:35 PM
Thank you for helping, Ankur!!!