How to pull Assign to and Work Notes in Incident Script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2017 03:14 AM
I am trying to create a script for email notification but unable to get "assign to" and "work notes." Any help?
var gr = new GlideRecord("incident");
gr.addEncodedQuery("priorityIN1,2^stateIN8,1,2^ORresolved_atRELATIVEGE@hour@ago@12");
gr.orderBy('sys_created_on');
gr.setLimit(20);
gr.query();
if (gr.getRowCount() > 0) {
template.print("<br/><b>Priority Tickets</b><br/>");
while (gr.next()) {
template.print(gr.getDisplayValue('sys_created_on') + " - <a href='" + baseUrl + gr.getLink() + "'>" + gr.getValue('number') + "</a> - " + "Prioirty: " + gr.getDisplayValue('priority') + " - " + "State: " + gr.getDisplayValue('state') + " <br/>" + "Short Description: " + gr.short_description + "<br/>" + gr.assign_to + gr.work_notes + "<br/><br/>");
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2017 03:22 AM
Hi Bryant,
If you assigned to field is not customized, then there might be a typo error. I checked in my instance for incident assigned to field and the name of the field was " assigned_to" and not gr.assign_to.
For getting the work notes, you have to use getJournalEntry() method. Check in wiki for more info on retrieving journal fields.
- var notes = current.work_notes.getJournalEntry(-1);
- var na = notes.split("\n\n"); //stores each entry into an array of strings
- for (var i = 0; i < na.length; i++) {
- gs.print(na[i]);
- }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2017 02:32 PM
Ah yes! It's "assigned_to" was misspelled. Any I was able to modify both to:
gr.getDisplayValue('work_notes')
gr.getDisplayValue('assigned_to')
and now getting the results I need.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2017 02:06 AM
Hi Bryant,
If I answered your query, could you please mark my answer as correct and resolve the thread