How to get work note single value in notification

Vinod S Patil
Tera Contributor

Hello Everyone,

How to get variable value from the RITM work note.

We have more than 10 values in the RITM work note but I need only two values in the notification. like below

DSF: dsf value
Mount: mount value.

How to achieve this please suggest me.





1 ACCEPTED SOLUTION

@Vinod S Patil 

okay got it, I assume your email script and notification is on sc_req_item table

use this email script to extract only those 2 values

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    var workNotes = current.work_notes.getJournalEntry(1); // Get the latest work note
    var dsfValue = '';
    var mountValue = '';

    // Extract DSF and Mount values
    var lines = workNotes.split('\n');
    for (var i = 0; i < lines.length; i++) {
        if (lines[i].startsWith('DSF:')) {
            dsfValue = lines[i].substring(4).trim();
        } else if (lines[i].startsWith('Mount:')) {
            mountValue = lines[i].substring(6).trim();
        }
    }

    template.print('DSF: ' + dsfValue + '<br/>Mount: ' + mountValue);

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

I was able to extract it in background script, so It should work for you as well in email script

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Vinod S Patil 

so in RITM work notes variable values are entered and you need to get only variable value?

Is DSF and Mount variable label in below? Share some screenshots

in which script you want to do this? business rule etc?

DSF: dsf value
Mount: mount value.

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 

Please find below attached RItm's work note screen shot.

I need only DFS Name and Share Name from the work note. I am using email script for this.

VinodSPatil_0-1744019416792.png

 

@Vinod S Patil 

okay got it, I assume your email script and notification is on sc_req_item table

use this email script to extract only those 2 values

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    var workNotes = current.work_notes.getJournalEntry(1); // Get the latest work note
    var dsfValue = '';
    var mountValue = '';

    // Extract DSF and Mount values
    var lines = workNotes.split('\n');
    for (var i = 0; i < lines.length; i++) {
        if (lines[i].startsWith('DSF:')) {
            dsfValue = lines[i].substring(4).trim();
        } else if (lines[i].startsWith('Mount:')) {
            mountValue = lines[i].substring(6).trim();
        }
    }

    template.print('DSF: ' + dsfValue + '<br/>Mount: ' + mountValue);

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

I was able to extract it in background script, so It should work for you as well in email script

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

Thank you @Ankur Bawiskar