How to efficiently report HR cases raised within 24 hours of KB article views
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello Community,
I’m working on a reporting requirement where we need to report HR cases raised within 24 hours of a user viewing a KB article.
I’m working on a reporting requirement where we need to report HR cases raised within 24 hours of a user viewing a KB article.
Here’s what I’ve tried so far:
- Script Include Approach with Report
I wrote a Script Include that loops through kb_use records, checks the user and timestamp, and then queries sn_hr_core_case for cases created within 24 hours of the KB view. This works fine for recent data (e.g., last 6 months), but when I remove the date filter to process all historical data, the script becomes extremely slow and impacts instance performance because kb_use has 200k+ records in my environment.
Example snippet:
var kbUse = new GlideRecord('kb_use');
kbUse.query();
while (kbUse.next()) {
var kbUser = kbUse.getValue('user');
var kbCreatedDate = kbUse.getValue('sys_created_on');
var startDateTime = new GlideDateTime(kbCreatedDate);
var endDateTime = new GlideDateTime(kbCreatedDate);
endDateTime.addDaysUTC(1);
var hrCase = new GlideRecord('sn_hr_core_case');
hrCase.addQuery hrCase.addQuery('sys_created_on', '>=', startDateTime);
hrCase.addQuery('sys_created_on', '<=', endDateTime);
hrCase.addQuery('opened_for', kbUser);
hrCase.query();
// Collect sys_ids2. Performance Analytics Widget
I tried using the same Script Include in a PA indicator, which worked for new data but failed for historical data jobs due to the same performance issue.
I tried using the same Script Include in a PA indicator, which worked for new data but failed for historical data jobs due to the same performance issue.
3. Database View
I attempted to create a database view joining kb_use and sn_hr_core_case on user fields, but couldn’t figure out how to apply the 24-hour condition effectively at the DB level.
I attempted to create a database view joining kb_use and sn_hr_core_case on user fields, but couldn’t figure out how to apply the 24-hour condition effectively at the DB level.
Challenge
The main issue is performance when processing large volumes of KB views and HR cases. I need a solution that:
- Handles historical data efficiently.
- Applies the 24-hour condition between KB view and HR case creation.
- Works for reporting or PA widgets without timing out.
Question
Has anyone implemented a similar requirement? What’s the best approach here?
- Is there a way to optimise the Script Include?
Any guidance or examples would be greatly appreciated!
Thanks!😊
Thanks!😊
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
Hello @NowNinja727 ,
Step-by-Step Guide to Collect Historical and Future Data
Step 1: Collect Historical Data
- Create a one-time data job to gather previous records.
- If you are setting up a new configuration, review past records for timelines.
- Use Performance Analytics (PA) for this task.
- Configure the job to collect 3–6 months of historical data (or as required).
- Run the job once and then deactivate it.
Purpose: This job is only for retrieving historical data (e.g., data from one year ago).
Step 2: Set Up Ongoing Data Collection
- Create another data job for future tracking.
- Schedule this job to run daily or monthly, based on your reporting needs.
- This job will ensure that all new records are captured and tracked consistently going forward.
Key Points
- The first job is one-time for historical data.
- The second job is recurring for future data.
- Use Performance Analytics for both jobs to ensure accurate reporting.
Please mark accepted solution if this resolves your query.
Thanks & Regards ,Supriya Waghmode |ServiceNow Consultant
