0

Method = GET

Relative path Path not required

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
try{
var IncNumber = request.queryParams.number;
if (IncNumber != '') {
//do somethiing with the values
var queryString = "number=" + IncNumber ;
var CHGrec = new GlideRecord('incident');
CHGrec.addEncodedQuery(queryString);
CHGrec.query();
if (CHGrec.hasNext()) {
while (CHGrec.next()) {
//set return values and send response
return {
"Status": "Success",
"Number": CHGrec.number,
"Description": CHGrec.description,
"Change Ownership group": CHGrec.getDisplayValue('assignment_group'),
"Change Owner": CHGrec.getDisplayValue('assigned_to'),
"Opened by": CHGrec.getDisplayValue('opened_by'),
"Priority": CHGrec.getDisplayValue('priority'),
"State": CHGrec.getDisplayValue('state'),
"Subcategory": CHGrec.getDisplayValue('u_subcategory'),
"Urgency": CHGrec.getDisplayValue('urgency'),
"Category": CHGrec.getDisplayValue('category'),
"Impact": CHGrec.getDisplayValue('impact'),
};
}
} else {
return {
"Status": "Failure",
"Message": "No Records Found",
};
}
}else {
return {
"Status": "Failure",
"Message": "Incident Number not provided",
};
}
} catch(ex) {
var message = ex.getMessage();
//set return values and send response
return {
"Status": "Error",
"ErrMessage": message
};
}
})(request, response);

REST API – GET Method – Pass Single Query
Working Code Asked question September 11, 2023