
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 06:58 AM
Scenario: I need to print one of the attribute value from JSON payload from 'Query parameter' to response body.
Example: In the payload it is given:
"site": {
"name":"abc demo"
}
So in this case i need to print the name value that is 'abc demo' in response body.
Issue: I wrote code but it is giving below error:
"message": "Cannot read property \"name\" from undefined",
Script:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var requestbodydata = request.queryParams.input[0];
var test = requestbodydata .site.name;
return(test);
}
Any idea how to solve this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 07:13 AM
Do one thing:
var requestbodydata = JSON.parse(request.queryParams.input[0]);
return requestbodydata.site.name;
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 07:24 AM
Thanks Aman,
working now

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 08:40 AM
Awesome!
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 07:27 AM
Hi,
what type of HTTP method it is?
Can you share the complete query parameters?
share what comes here
var requestbodydata = request.queryParams;
gs.info("JSON " + JSON.stringify(requestbodydata));
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader