- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 04:39 AM
When a user is offboarded or marked as inactive, identify the knowledge articles where the workflow is published and the author is the current user. Update the author to the user's manager and send a single notification to the manager containing a list of the KB article numbers.
But it is generating multiple emails to its manager instead of single email. Please suggest any solution how to solve this issue.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 02:56 PM - edited 03-03-2025 02:57 PM
Hello @Rina Mal
Updated Async Business Rule:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if (!current.active) {
var manager = current.manager;
if (!manager) {
return;
}
var kb = new GlideRecord("kb_knowledge");
kb.addQuery("workflow_state", "published");
kb.addQuery("author", current.sys_id);
kb.query();
var updatedKBs = [];
while (kb.next()) {
kb.author = manager;
kb.update();
updatedKBs.push(kb.number.toString()); // Collect updated KB numbers
}
// Send one email if there are updates
if (updatedKBs.length > 0) {
var kbNumbersStr = updatedKBs.join(", ");
gs.eventQueueUnique("event_name", current, manager, kbNumbersStr);
}
}
})(current, previous);
Additional Information: If you want to construct the e-mail body from your Business Rule, then below is the updated code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if (!current.active) {
var manager = current.manager;
if (!manager) {
return;
}
var kb = new GlideRecord("kb_knowledge");
kb.addQuery("workflow_state", "published");
kb.addQuery("author", current.sys_id);
kb.query();
var updatedKBs = [];
while (kb.next()) {
kb.author = manager;
kb.update();
// Construct table row for each KB article
var kbLink = gs.getProperty('glide.servlet.uri') + 'kb_view.do?sys_id=' + kb.sys_id;
updatedKBs.push("<tr><td><a href='" + kbLink + "'>" + kb.number + "</a></td><td>" + kb.short_description + "</td></tr>");
}
// If updates happened, send an event with the formatted table
if (updatedKBs.length > 0) {
var kbTable = "<table border='1' cellpadding='5' cellspacing='0' style='border-collapse: collapse;'>" +
"<tr><th>KB Number</th><th>Short Description</th></tr>" +
updatedKBs.join("") +
"</table>";
gs.eventQueue("kb_update_notify", current, manager.sys_id, kbTable);
}
}
//gs.log(updatedKBs); // for logging purposes
})(current, previous);
1. System Policy > Events > Registry -- Created one sample event as shown below
2. Created System Notification > Email > Notifications
3. Updated one dummy user active to false in sys_user table and here is one e-mail sent:
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 06:22 AM
You may want to use
- Flow Designer: which would be triggered whenever there is an updated on sys_user table if a record is becoming inactive. Within the Flow, you have the flexibility to check and KB articles where the user is an author, you can store those within a Flow Variable, ...
- Notification: To be sent at the end of the flow and it should contain. (You can use Event to trigger notification, and pass the content from the Flow Variable "KB Articles" as an event parameter). You would end up having one notification for all KBs
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 06:51 AM
Thank you for your response.
Here I am implementing this using an async business rule on the sys_user table when Active is set to false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 01:12 PM
@Rina Mal
Could you use the following instead of "gs.eventQueueUnique("event_name", kb, manager, kbNumbersStr);"?
gs.eventQueue("event_name", current, manager, kbNumbersStr);
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 02:56 PM - edited 03-03-2025 02:57 PM
Hello @Rina Mal
Updated Async Business Rule:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if (!current.active) {
var manager = current.manager;
if (!manager) {
return;
}
var kb = new GlideRecord("kb_knowledge");
kb.addQuery("workflow_state", "published");
kb.addQuery("author", current.sys_id);
kb.query();
var updatedKBs = [];
while (kb.next()) {
kb.author = manager;
kb.update();
updatedKBs.push(kb.number.toString()); // Collect updated KB numbers
}
// Send one email if there are updates
if (updatedKBs.length > 0) {
var kbNumbersStr = updatedKBs.join(", ");
gs.eventQueueUnique("event_name", current, manager, kbNumbersStr);
}
}
})(current, previous);
Additional Information: If you want to construct the e-mail body from your Business Rule, then below is the updated code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if (!current.active) {
var manager = current.manager;
if (!manager) {
return;
}
var kb = new GlideRecord("kb_knowledge");
kb.addQuery("workflow_state", "published");
kb.addQuery("author", current.sys_id);
kb.query();
var updatedKBs = [];
while (kb.next()) {
kb.author = manager;
kb.update();
// Construct table row for each KB article
var kbLink = gs.getProperty('glide.servlet.uri') + 'kb_view.do?sys_id=' + kb.sys_id;
updatedKBs.push("<tr><td><a href='" + kbLink + "'>" + kb.number + "</a></td><td>" + kb.short_description + "</td></tr>");
}
// If updates happened, send an event with the formatted table
if (updatedKBs.length > 0) {
var kbTable = "<table border='1' cellpadding='5' cellspacing='0' style='border-collapse: collapse;'>" +
"<tr><th>KB Number</th><th>Short Description</th></tr>" +
updatedKBs.join("") +
"</table>";
gs.eventQueue("kb_update_notify", current, manager.sys_id, kbTable);
}
}
//gs.log(updatedKBs); // for logging purposes
})(current, previous);
1. System Policy > Events > Registry -- Created one sample event as shown below
2. Created System Notification > Email > Notifications
3. Updated one dummy user active to false in sys_user table and here is one e-mail sent:
Hope that helps!