The CreatorCon Call for Content is officially open! Get started here.

Get the Activity Log of an Incident

xantor
Kilo Expert

Good day folk,

I've created a custom printing form for my Incidents that prints out everything as I want it to be. I only have one problem though...

I cannot seem to get the activity of a specific incident!

I keep getting "unspecified". Where is the Activity Log for Incidents stored? And how is it referenced to an Incident?

I'd like to get the Activity Log in String or HTML format doesn't matter which.

Any help would be great!

5 REPLIES 5

User212122
Kilo Expert

Hi Gysbertus,



Activity Formatter is enabled by default on the Task [task] table and other tables that extend the Task table, such as the [incident] table. It is also enabled on the Approvals [sysapproval_approver] table.



For custom tables please use below points to create new Activity Formatter


Creating an Activity Formatter

Administrators can create an activity formatter for any audited table.


  1. Navigate to System UI > Formatters.
  2. Click New.
  3. Enter a name for the formatter, such as Activities (task).
  4. Select a Table.
  5. Enter activity.xml in the Formatter field.
  6. Leave the Type as Formatter.
  7. Click Submit.
  8. Open the form on which the new formatter should appear.
  9. Right-click the form header and select the appropriate option for your version:
    • Fuji or later: Configure > Form Layout
    • Eureka or earlier: Personalize > Form Layout
  10. Add the new formatter to the form.
  11. Right-click the Activity header in the form and choose Personalize Activity to select the fields of interest.



Regards,


Sunil Arya


(Mark the answer correct or helpful if it helps you achieve your goal)


Thank you for the reply, to clarify - I am trying to read the work_notes from the Incident table... It's just giving me a blank <text area>



Here is the supposed code to get it:



var notes = current.work_notes.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n'


var na = notes.split("\n\n");     //stores each entry into an array of strings



for (var i = 0; i < na.length; i++)    


  document.getElementById("txtActivity").value += (na[i]) + "\n";



But it's not working at all



current is a server side object and document.getElementById is client side. Don't mix both.



Using Journal Fields - ServiceNow Wiki


xantor
Kilo Expert

*** UPDATE ***


I have managed to get the Work Notes and the Comments for an specific Incident and set it to the <text area> on my custom page. Here is how...



Lookup_Journal(gr.sys_id); //Use the Incident Sys_ID to query the Element ID



function Lookup_Journal(sysID)


{



  var gr = new GlideRecord('sys_journal_field');


  gr.addQuery('element_id', sysID);


  gr.query();


  while (gr.next()) {



  document.getElementById("txtcomments").value += "Created by: " + gr.sys_created_by + "\n";


  document.getElementById("txtcomments").value += "Element: " + gr.element + "\n";


  document.getElementById("txtcomments").value += "Element ID: " + gr.element_id + "\n";


  document.getElementById("txtcomments").value += "Value: " + gr.value + "\n";


  document.getElementById("txtcomments").value += "Name: " + gr.name + "\n";


  document.getElementById("txtcomments").value += "SysID: " + gr.sys_id + "\n";


  document.getElementById("txtcomments").value += "========================================================================== \n";


  }



}



Now, to figure out how to get the Incident state change history, assigned group, etc...


Feel free to use...