0

HTTP method – GET

Relative path – /{number} (Copy exact)

Resource path created automatically – /api/71907/incident_managment/{number}

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
try {
var IncNumber = request.pathParams.number;
if (IncNumber != '') {
//do somethiing with the values
// var queryString = "number=" + IncNumber ;
var queryString = "numberIN" + IncNumber;
var CHGrec = new GlideRecord('incident');
CHGrec.addEncodedQuery(queryString);
CHGrec.query();
var incident_data = {};
var incident_details = [];
if (CHGrec.hasNext()) {
while (CHGrec.next()) {
//set return values and send response
incident_data = {
"Number": CHGrec.number.toString(),
"Description": CHGrec.description.toString(),
"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'),
};
incident_details.push(incident_data);
}
return {
"Incident Details": incident_details,
};
} 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);

RESULT :

<span class="ng-binding">{
  "result": {
    "Incident Details": [
      {
        "Number": "INC0011913",
        "Description": "",
        "Change Ownership group": "VIP Users",
        "Change Owner": "",
        "Opened by": "System Administratorde",
        "Priority": "5 - Planning",
        "State": "New",
        "Subcategory": null,
        "Urgency": "3 - Low",
        "Category": "Inquiry / Help",
        "Impact": "3 - Low"
      },
      {
        "Number": "INC0011914",
        "Description": "",
        "Change Ownership group": "VIP Users",
        "Change Owner": "",
        "Opened by": "System Administratorde",
        "Priority": "5 - Planning",
        "State": "New",
        "Subcategory": null,
        "Urgency": "3 - Low",
        "Category": "Inquiry / Help",
        "Impact": "3 - Low"
      }
    ]
  }
}</span>
Rest API – Get Method – Pass Multiple record with comma seprated
Working Code Edited question September 11, 2023