- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 12:16 AM - edited 04-15-2025 12:18 AM
var err= new sn_ws_err.NotFoundError('The resource you requested is not part of the API.');
gs.info(JSON.stringify(err))
In the above example, I want to access the "err" object in the api to log the error response. But it is
empty object
{} for gs.info(JSON.stringify(err))
[object NotFoundError] for gs.info(err);
But I want the it to be in the below format:
Is it possible to access it before the response is sent?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 12:40 AM
Hello @Bharath24
This cannot be printed before you have run it. Obviously it will give you empty object, because it is just an empty object as it says. The key value pairs are assigned after it is run. Otherwise what will it assign ?
You cannot tap the responseBody, you need to set another method to call this method, and then store the response body and then print it. This cannot be tapped during configuration, only after execution.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 12:57 AM
it looks to me that it comes from platform level and is handled at the API interaction so you won't be able to access that. these are coming from sn_ws_err namespace
You can create your own custom error objects if required, check this link
Scripted REST API Error Objects
You are already getting the correct JSON in response, this is from the developer site
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-15-2025 12:40 AM
Hello @Bharath24
This cannot be printed before you have run it. Obviously it will give you empty object, because it is just an empty object as it says. The key value pairs are assigned after it is run. Otherwise what will it assign ?
You cannot tap the responseBody, you need to set another method to call this method, and then store the response body and then print it. This cannot be tapped during configuration, only after execution.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 12:57 AM
it looks to me that it comes from platform level and is handled at the API interaction so you won't be able to access that. these are coming from sn_ws_err namespace
You can create your own custom error objects if required, check this link
Scripted REST API Error Objects
You are already getting the correct JSON in response, this is from the developer site
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader