Create a notification when reaching 20 download attempts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 12:44 PM
I'm looking to create a notification, when 20 download attempts (knowledge articles) are made by any logged in user (Customer Support Portal) during a 24 hour period. How/where would I run a query to provide/show that information? And, tie it to a notification?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 12:58 PM
Hi @MStritt ,
The main part , how to count the download ( or attempts ) for this notification else you can apply required filter and trigger the notification.
The kb_use table count the view but not the download.
In the below thread Jaspal Singh has given an idea but that from system log tables, you can check.
-Thanks,
AshishKMishra
Please accept solution and mark helpful for others if it helps you
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 08:11 PM - edited ‎11-07-2023 08:12 PM
Hi @MStritt
Let's try the below approach.
1. Create an Event Registry in the Knowledge [kb_knowledge] for the Notification.
2. Create a Script Action triggered when the event attachment.read fired.
3. Add condition only runs when table is kb_knowledge. Then calculate the total event in the day to verify if it reaches 20 times.
Sample below.
var date_query = "sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()";
var gaEvent = new GlideAggregate('sysevent');
gaEvent.addQuery('name', 'attachment.read');
gaEvent.addQuery('table', current.getTableName());
gaEvent.addQuery('instance', current.getUniqueValue());
gaEvent.addEncodedQuery(date_query);
gaEvent.groupBy('instance');
gaEvent.addAggregate('COUNT', 'sys_id');
gaEvent.query();
if(gaEvent.next()){
var total = parseInt(gaEvent.getAggregate('COUNT', 'sys_id'));
if(total === 20){
var grKnowledge = new GlideRecord('kb_knowledge');
if(grKnowledge.get(current.table_sys_id)){
gs.eventQueue('<your_notify_event_name>', grKnowledge); //Replace your event name
}
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 08:23 PM
Hi @Tai Vu ,
Thanks for sharing code here , does this code count the total downloads or just read.
-Thanks
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2023 08:56 PM
Hi @AshishKM
The approach above is referenced from your comment.
One observation I've made is that when we click on the attachment, it opens the following URL.
URL: https://<instance_name>/sys_attachment.do?sys_id=<the_sys_id_attachment_record>
Following this, the event attachment.read gets triggered.
In scenarios where the instance utilizes the Document Viewer in the Knowledge [kb_knowledge] table, we may need to explore another way to identify when users open the Viewer or download the content.
Cheers,
Tai Vu