Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# IncidentHelper - getOpenIncidents

**Purpose:** Script Include (client-callable via GlideAjax) that returns a JSON array of active incident records.

**Usage Example**
```js
var ga = new GlideAjax('IncidentHelper');
ga.addParam('sysparm_name','getOpenIncidents');
ga.getXMLAnswer(function(response){
var list = JSON.parse(response || '[]');
console.log(list);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example of what the output will look like? This will help others more easily understand what the code does.

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

// IncidentHelper - Script Include
var IncidentHelper = Class.create();
IncidentHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOpenIncidents: function() {
var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.orderByDesc('sys_created_on');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you ordering descending on created on? Add this to your readme or a comment.

gr.setLimit(50);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you limiting to 50? Can you add this to the readme or include a comment?

gr.query();

var list = [];
while (gr.next()) {
list.push({
number: gr.getValue('number'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you can include in the readme that this code now only pushes these attributes, and not the full Incident?

short_description: gr.getValue('short_description'),
sys_id: gr.getValue('sys_id'),
priority: gr.getValue('priority')
});
}
return JSON.stringify(list);
},
type: 'IncidentHelper'
});
Loading