- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have a provider notification ([sys_notification]) that runs against the [live_notification] table and on record change, insert, and when the field name is work_notes or comments (category is 'connect'). When someone sends an @mention, the recipient gets the notification in their "bell". When they click the notification, instead of being taken to the task (I have been testing with [sn_customerservice_case]) from which they were mentioned, the [live_notification] record is loaded.
I noticed that, if I modify the related [ui_notification_inbox] record, changing the target_table from [live_notification] to [sn_customerservice_case], then the notification loads the case. After creating a BR on the [ui_notification_inbox] table (runs before insert, when the trigger is my provider notification), I can see the BR script running, but the target_table is not being updated.
My assumption is that, when the record is inserted, BRs do not run, so I had a look at the existing [live_notification] BRs and found one called "Send Notification", which looks like it must create the [ui_notification_inbox] record, but it uses an API for which I cannot find any documentation. I updated the script, but it did not change how the [ui_notification_inbox] record is created.
Anyone know how to control [ui_notification_inbox] records or how to make the notifications point to my desired record?
Here is the "Send Notification" BR script:
(function executeRule(current, previous /*null when async*/) {
var profile = current.profile;
if(!profile) {
profile = new GlideappLiveProfile().getIDFromProfileOrUser(current.user);
if (!profile)
return;
current.setValue("profile", profile);
current.update();
}
var liveGroupProfileGR = new GlideRecord("live_group_profile");
liveGroupProfileGR.setWorkflow(false);
liveGroupProfileGR.addQuery("document", current.document);
liveGroupProfileGR.addQuery("table", current.table);
liveGroupProfileGR.addQuery("type", "!=", "support");
liveGroupProfileGR.query();
if(liveGroupProfileGR.next()) {
var liveGroupMemberGR = new GlideRecord("live_group_member");
liveGroupMemberGR.setWorkflow(false);
liveGroupMemberGR.addQuery("group", liveGroupProfileGR.getUniqueValue());
liveGroupMemberGR.addQuery("member", profile);
liveGroupMemberGR.addQuery("state", "!=", "inactive");
liveGroupMemberGR.query();
if(liveGroupMemberGR.next()) {
return;
}
}
// The following section was added to allow @mention notifications to trigger a notification that points to the task record instead of the live_notification record.
gs.info('[Notification Update] Running update script in Send Notification BR.');
var documentGr = current.document.getRefRecord();
if (documentGr) {
gs.info('[Notification Update] Found the live_notification\'s document record: ' + documentGr.getUniqueValue());
var targetTable = documentGr.sys_class_name;
if (targetTable) {
gs.info('[Notification Update] Document table: ' + targetTable);
//current.table = targetTable;
//current.document = documentGr.getUniqueValue();
} else {
gs.info('[Notification Update] No document table returned.');
}
}
new GlideNotificationBroadcaster().broadcast({
title: current.title,
message: current.message,
table: targetTable, //current.table,
document: documentGr.getUniqueValue() //current.document
}, profile);
})(current, previous);I can see it runs by checking the system log and the targetTable/documentGr records are what I expect.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Sorry I omitted a few key things needed to make this work. The record instance in the event will not be [live_notification] so you can leave the table field empty in the notification and the event. The table for the record will be whatever record the mention is on e.g incident (second gr parameter on gs.eventQueue()).
Use the event parameters to pass the target user to the notification.
(function executeRule(current, previous /*null when async*/) {
var mentiodOnGr = new GlideRecord(current.getValue("table"));
if (mentiodOnGr.get(current.getValue("document"))) {
gs.eventQueue("mention.task", mentiodOnGr, /*event.parm1 set to mentioned user*/ current.getValue("user"));
}
})(current, previous);
Recipient in parm1 on the notification:
And then you can transfer the notification condition from the [sys_notification] record to the business rule as you have easy access to both the [live_notification] and the target record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
I made the following modifications:
1. Modified BR
2. Modified the Notification (removed table and updated 'who will receive')
3. Modified the Event Registration (removed the table value)
When I load up a case and @mention someone, I see the event and the [ui_notification_inbox] record and thus, saw the notification, which took me to the case.
Thanks.