How to add rejected comments in workflow notification activity for a knowledge article
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 04:58 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 05:31 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 02:07 AM
Hi @Ankur Bawiskar ,
Thank you for your response. It is not working. It is still blank in the notification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 03:57 AM
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?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 04:40 AM
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.