Skip to content

Instantly share code, notes, and snippets.

@paulsena
Created April 15, 2014 16:28
Show Gist options
  • Save paulsena/10745542 to your computer and use it in GitHub Desktop.
Save paulsena/10745542 to your computer and use it in GitHub Desktop.
ServiceNow Scripted WS that returns the incidents created for a certain user. Returns Incident Number, State Value, and State Display Name for each incident. Accepts a few parameters for filtering such as callerId, active, orderBy, orderByDesc, firstRow, lastRow, limit. Uses a JSON object to build up the dynamic SOAP response data then passes it…
response.response = getUserIncidents();
function getUserIncidents() {
var recordSet= [];
var callerId = request.caller_id;
var active = request.active;
var orderBy = request.order_by;
var orderByDesc = request.order_by_desc;
var firstRow = request.first_row ? request.first_row : 1;
var lastRow = request.last_row ? request.last_row : 9999999;
var limit = request.limit ? request.limit : 9999999;
var grInc = new GlideRecord('incident');
grInc.addQuery('caller_id.user_name', callerId);
grInc.addQuery('active', active);
grInc.orderBy(orderBy);
grInc.orderByDesc(orderByDesc);
grInc.setLimit(limit);
grInc.query();
for (var rowCntr=1; rowCntr<=grInc.getRowCount() && rowCntr <= limit; rowCntr++) {
grInc.next()
if (rowCntr >= firstRow && rowCntr <= lastRow) {
var record = {};
record.incident_state = grInc.incident_state.toString();
record.incident_state_display = grInc.incident_state.getDisplayValue();
record.number = grInc.number.toString();
recordSet.push(record);
}
}
var result = { 'recordSet': { 'record' : recordSet}};
return new XMLHelper().toXMLDoc(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment