Need to display all the updates on notification

suuriyas
Tera Contributor

HI Community,

 

I have a requirement, when there is update happened on major incident then only last 3 updates are shown in mail but i need to show all the updates and it seems like there is oob email script called getLastThreeActivityLog is used.

script:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
            var activities = current.incident_alert.source_incident.actions_taken.getJournalEntry(3);
            var activityArray = activities.split("\n\n");
            template.print("<br/>");
            for(var i = 0; i < activityArray.length; i++)
                template.print(activityArray[i]+"<br/>");

})(current, template, email, email_action, event);
 
now instead of last 3 updates i need all the updates to be shown.
How can we achieve this?
 
Thanks in Advance
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriyas 

then use this

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    template.print('Action taken History:' + '<br/>');
    var gr = new GlideRecord('sys_journal_field');
    gr.orderByDesc('sys_created_on'); // show the latest and then old
    gr.addQuery('element', 'actions_taken');
    gr.addQuery('element_id', current.incident_alert.source_incident);
    gr.query();
    while (gr.next()) {
        template.print(gr.value + '<br/>');
    }

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriyas 

Would you mind closing your earlier questions by marking appropriate response as correct?

Members have invested their time and efforts in helping you.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Murtaza Saify
Tera Contributor

use this

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Retrieve all journal entries by passing a large number (e.g., 1000)
var activities = current.incident_alert.source_incident.actions_taken.getJournalEntry(1000);

// Split the activities into individual entries
var activityArray = activities.split("\n\n");

// Print each activity entry
template.print("<br/>");
for (var i = 0; i < activityArray.length; i++) {
template.print(activityArray[i] + "<br/>");
}
})(current, template, email, email_action, event);