- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 05:44 AM
Hello,
I am trying to parse the Rest Message response but not able to get the proper data out.
after executing the below code through REST Message.
var response = request.execute();
var requestBody = response.getBody();
var httpStatus = response.getStatusCode();
var parsedJSON = JSON.stringify(JSON.parse(requestBody));
gs.info("Today Testing: "+parsedJSON);
return parsedJSON;
I can see the response message as below
{"data": {"client_id": "XXXXXXXX", "otp_sent": true,
"if_number": true, "valid_aadhaar": true}, "status_code": 200, "message_code": "success",
"message": "OTP Sent.", "success": true}
Now I am trying to parse the data and get the client_id to return back to client script but above script returning the undefined value. please suggest a way to get key value results.
Thanks,
Prudhvi
Solved! Go to Solution.
- Labels:
-
IntegrationHub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2022 02:34 AM
Hi,
that's the issue
since it's not a string it cannot be parsed by next line
update as this; change in bold
function responseParser(answer){
var result = answer.responseXML.getElementsByTagName("answer");
alert(result); // what came here
result = JSON.parse(result);
g_form.setValue('aadhar_details', result.data.client_id);
}
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
04-27-2022 02:34 AM
Hi,
that's the issue
since it's not a string it cannot be parsed by next line
update as this; change in bold
function responseParser(answer){
var result = answer.responseXML.getElementsByTagName("answer");
alert(result); // what came here
result = JSON.parse(result);
g_form.setValue('aadhar_details', result.data.client_id);
}
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
04-27-2022 03:03 AM
Hi Ankur,
It still not setting the client ID. I am using JSON.parse in script and JSON.stringfy in client script and I tried vise versa as well but no luck.
Regards,
Prudhvi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2022 05:11 AM
It's working now, I have updated my client script with below line.
var result = answer.responseXML.documentElement.getAttribute("answer"); from var result = answer.responseXML.getElementsByTagName("answer");
and now it is working as expected.
Thank you all for your help and support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2022 05:47 AM
Glad to know.
Did you mistakenly marked other response as correct?
Would you mind marking my response as correct as my script worked for you.
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
04-27-2022 05:54 AM
The issue was in your client script which I pointed out.
The answer marked as correct doesn't relate to the question asked.
Request you to kindly mark appropriate response as correct.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader