0% found this document useful (0 votes)
2 views1 page

Incident Retrieval API Process

The document contains JavaScript code for processing REST API requests related to incidents in a system. It extracts a 'sys_id' from the request, retrieves incident details from a database, and returns the information or an error message based on the existence of the incident. Two alternative code snippets are provided for achieving similar functionality with slight variations in implementation.

Uploaded by

nadeemtalha072
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Incident Retrieval API Process

The document contains JavaScript code for processing REST API requests related to incidents in a system. It extracts a 'sys_id' from the request, retrieves incident details from a database, and returns the information or an error message based on the existence of the incident. Two alternative code snippets are provided for achieving similar functionality with slight variations in implementation.

Uploaded by

nadeemtalha072
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

(function process(request, response) {

// Extract the sys_id from the request


var sysId = [Link].sys_id;

if (!sysId) {
[Link](400); // Bad Request
return [Link]({ error: "sys_id parameter is required" });
}

var incidentGR = new GlideRecord('incident');


if ([Link](sysId)) {
// Build the response
var result = {
sys_id: [Link]('sys_id'),
number: [Link]('number'),
short_description: [Link]('short_description'),
priority: [Link]('priority'),
state: [Link]('state'),
};
[Link](200); // OK
[Link](result);
} else {
[Link](404); // Not Found
[Link]({ error: "Incident not found for sys_id: " + sysId });
}
})(request, response);

/
*----------------------------------------------------------------------------------
---------*/

/* Alternative code */

/
*----------------------------------------------------------------------------------
---------*/

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

// implement resource here

var sys_id = [Link].sys_id;


var gr = new GlideRecord('incident');
[Link]('sys_id', sys_id);
[Link]();
if ([Link]()) {
var body = {};
[Link] = [Link];
body.short_description = gr.short_description;

[Link](body);
}

})(request, response);

You might also like