Work notes list maximum 3 in quick message

ShuRiseUp2023
Tera Expert

Hi Community,

I need to create a quick message for the P1/P2 incidents to show all the work notes have been added to this incident so far. In the quick message, I use ${work_notes} to pull the variable but the maximum work notes number that listed in the quick message is 3. It always shows the latest 3 work notes of this incident. How to show all the work notes in the quick message? 

Thanks

1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

Hi @ShuRiseUp2023 ,

 

1. you can set the system property value to -1

glide.email.journal.lines

ChaitanyaILCR_0-1752626812195.png

note: this would be reflecting in all over the system

 

 

2. else follow this approach 

https://www.servicenow.com/community/itsm-forum/can-we-add-mail-script-to-the-quick-message/td-p/649...

 

create a Before insert update BR on the sys_email and sys_email_draft table

 

ChaitanyaILCR_2-1752628526610.png

with script

ChaitanyaILCR_3-1752628558083.png

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var targetRecord = new global.GlideRecordUtil().getGR(current.getValue('target_table'), current.getValue('target_record'));
    if (targetRecord.isValidRecord()) {
        current.setValue('body', current.getValue('body').replaceAll('{placeHolderWorknotes}', targetRecord.work_notes.getJournalEntry(-1)).replaceAll('\n','<br/>'));
    }


})(current, previous);

 

add the key Word {placeHolderWorknotes} in whichever the quick message you want 

The BR parses it and replaces it with the worknotes

 

ChaitanyaILCR_1-1752628478666.png

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi @ShuRiseUp2023  ,, Good morning,.....!

When you use ${work_notes} in your quick message or notification, ServiceNow by default only pulls the last three work notes — that’s controlled internally by how the notification formatter works, and there isn’t a simple system property to change it.

If you really want to include all work notes, the recommended way is to create a mail script that manually queries the sys_journal_field table for that incident and builds the list yourself.

 

xample of what that mail script

 

// Mail script to get all work notes
(function runMailScript(current, template, email, email_action, event) {
  var notes = '';
  var gr = new GlideRecord('sys_journal_field');
  gr.addQuery('element_id', current.sys_id); // link to the incident
  gr.addQuery('element', 'work_notes'); // only work notes
  gr.orderBy('sys_created_on'); // oldest first
  gr.query();
  while (gr.next()) {
    notes += '- ' + gr.sys_created_on.getDisplayValue() + ': ' + gr.value + '\n';
  }
  template.print(notes);
})(current, template, email, email_action, event);

quick message, instead of ${work_notes}, insert

${mail_script:your_script_name}

 

Thank you for your response. I have first tried use mail script, but it seems like not working in quick message. it's ignored. 

Chaitanya ILCR
Kilo Patron

Hi @ShuRiseUp2023 ,

 

1. you can set the system property value to -1

glide.email.journal.lines

ChaitanyaILCR_0-1752626812195.png

note: this would be reflecting in all over the system

 

 

2. else follow this approach 

https://www.servicenow.com/community/itsm-forum/can-we-add-mail-script-to-the-quick-message/td-p/649...

 

create a Before insert update BR on the sys_email and sys_email_draft table

 

ChaitanyaILCR_2-1752628526610.png

with script

ChaitanyaILCR_3-1752628558083.png

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var targetRecord = new global.GlideRecordUtil().getGR(current.getValue('target_table'), current.getValue('target_record'));
    if (targetRecord.isValidRecord()) {
        current.setValue('body', current.getValue('body').replaceAll('{placeHolderWorknotes}', targetRecord.work_notes.getJournalEntry(-1)).replaceAll('\n','<br/>'));
    }


})(current, previous);

 

add the key Word {placeHolderWorknotes} in whichever the quick message you want 

The BR parses it and replaces it with the worknotes

 

ChaitanyaILCR_1-1752628478666.png

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

Thank you so much for your response. I tried exactly the same as you descripted here. but still not working. In your BR,

Then I checed the sys_email table and found out we should use instance instead of target_record. in sys_email table, 

var targetRecord = new global.GlideRecordUtil().getGR(current.getValue('target_table'), curent.getValue('instance')); 

 

Thank you so much