Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Beto
Mega Guru

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/>");  

          }  

    }

3 REPLIES 3

vinothkumar
Tera Guru

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.



  1. var notes = current.work_notes.getJournalEntry(-1);  
  2. var na = notes.split("\n\n");       //stores each entry into an array of strings  
  3. for (var i = 0; i < na.length; i++) {  
  4.       gs.print(na[i]);  
  5. }

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.


Hi Bryant,



If I answered your query, could you please mark my answer as correct and resolve the thread