Get the Activity Log of an Incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2016 04:30 AM
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!
- Labels:
-
Scripting and Coding
- 17,656 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2016 05:43 AM
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.
- Navigate to System UI > Formatters.
- Click New.
- Enter a name for the formatter, such as Activities (task).
- Select a Table.
- Enter activity.xml in the Formatter field.
- Leave the Type as Formatter.
- Click Submit.
- Open the form on which the new formatter should appear.
- Right-click the form header and select the appropriate option for your version:
- Add the new formatter to the form.
- 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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2016 07:27 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2016 07:44 AM
current is a server side object and document.getElementById is client side. Don't mix both.
Using Journal Fields - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 12:46 AM
*** 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...