Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

How to add rejected comments in workflow notification activity for a knowledge article

Joshuu
Kilo Sage

Hi All,

 

when an article is rejected, an email notification should send to a specific group including the rejected comments from the approval.

 

I have added a notification activity in the workflow. Notification is getting triggered, but comments are not getting added. I have added below scripts in the workflow. Could you please check. 

 

Run script:

 

var approverComments = "";
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id); // Link to the current knowledge article
gr.query();
while (gr.next()) {
    if (gr.comments) {
        approverComments += gr.comments + "\n";
    }
}
workflow.scratchpad.rejectionComments = approverComments;

 

 

Body of notification activity:

 

Hello,

Knowledge Article ${display_number} has been rejected and requires your review. Please update the article with the information requested below.

Article title: ${short_description}

Comments: ${workflow.scratchpad.rejectionComments}

Thank you. 

 

 

Regards,

Priyanka.

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@Joshuu 

use this script

var gr = new GlideRecord('sysapproval_approver');
        gr.addQuery('sysapproval', current.sys_id); // Link to the current knowledge article
        gr.query();
        if (gr.next()) {
            var latestComments = gr.comments.getJournalEntry(1); // get the latest comment
            var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
            latestComments = latestComments.replace(dateRE, ''); // use regex and get only the comment without name & date
            workflow.scratchpad.rejectionComments = latestComments;
        }

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

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

Hi @Ankur Bawiskar ,

 

Thank you for your response. It is not working. It is still blank in the notification.

@Joshuu 

did you check if user added comments or not while rejecting?

Also did you check if the query worked and it went inside the IF condition?

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

Hi @Ankur Bawiskar ,

 

sysapproval is not capturing the knowledge number. Can we use any other condition? I have tried the below but still not working.

 

gr.addQuery('document_id.number', current.number);