What is the API of new sn_ws_err.NotFoundError
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2022 12:57 PM
Hi,
Has anyone figured out the API for new sn_ws_err.NotFoundError to grab the message/status that it holds inside?
example:
var err = new sn_ws_err.NotFoundError('No Incident found');
I attempted the following options and nothing came out:
gs.info(err); // Outputs [Object NotFoundError]
gs.info(JSON.stringify(err)); // Outputs nothing
gs.info(Object.keys(err)); // Outputs nothing
for (var k in err) { // This does not even execute
gs.info(k);
gs.info(err[k])
}
I know one of the errors has the following methods:
var myError = new sn_ws_err.ServiceError();
myError.setStatus(442);
myError.setMessage('Some Message');
myError.setDetail('Some details.');
Has anyone managed to find how to retrieve status/message/detail out of the generated object?
Reason: there is code inside ServiceNow that makes use of these calls, and fails to return a sensible message when those functions are called. So it makes it really hard to log, or diverge behavior if those issues are found.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 10:26 AM
Hey rdelpeso1,
From a scripted rest api rest resource, I've used error setting like this:
response.setError(new sn_ws_err.BadRequestError("No Matching rules found"));
return;
This yields a response result like this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 11:08 AM
"API" stands for "Application Programming Interface," and it refers to a set of rules and protocols that allow different software programs to communicate with each other. An API defines how to access a specific service or application and how to use its functionality.
The "new" keyword in programming languages like JavaScript, C# and Java is used to create a new instance of an object or class. When the "new" keyword is used in combination with a constructor function, it creates a new object with the properties and methods defined in the constructor.
Example:
@rdelpeso1 wrote:Hi,
Has anyone figured out the API for new sn_ws_err.NotFoundError to grab the message/status that it holds inside?
example:
var err = new sn_ws_err.NotFoundError('No Incident found');
I attempted the following options and nothing came out:
gs.info(err); // Outputs [Object NotFoundError]
gs.info(JSON.stringify(err)); // Outputs nothing
gs.info(Object.keys(err)); // Outputs nothing
for (var k in err) { // This does not even execute
gs.info(k);
gs.info(err[k])
}
I know one of the errors has the following methods:
var myError = new sn_ws_err.ServiceError();
myError.setStatus(442);
myError.setMessage('Some Message');
myError.setDetail('Some details.');
Has anyone managed to find how to retrieve status/message/detail out of the generated object?
Reason: there is code inside ServiceNow that makes use of these calls, and fails to return a sensible message when those functions are called. So it makes it really hard to log, or diverge behavior if those issues are found.
Thanks
class MyClass {
constructor(param1, param2) {
this.param1 = param1;
this.param2 = param2;
}
}
const myObject = new MyClass("value1", "value2");
console.log(myObject.param1); // Output: "value1"
console.log(myObject.param2); // Output: "value2"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 03:36 AM
"Programming interface" means "Application Programming Point of interaction," and it alludes to a bunch of decides and conventions that permit different programming projects to speak with one another. A Programming interface characterizes how to get to a particular help or application and how to utilize its usefulness. The "new" watchword in programming dialects like JavaScript, C# and Java is utilized to make another occasion of an article or class. When the "new" watchword is utilized in mix with a constructor capability, it makes another item with the properties and strategies characterized in the constructor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 01:20 PM
All of the methods of sn_ws_err.ServiceError return the source object (this) to allow for method chaining. This is a standard javascript paradigm.