- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 03:10 AM
hello all,
i have a requirement where I have to create a report based on priority changes on incident
for this I want to create a metric defination
how ever I want to restrict the definition in a way that it should create a metric instance only when priority is actually changed but not set during initial creation
I want script for the same
help will be appriciated
any other alternative that can capture the priority change such as scrip ton sys_audit history will also be considered
thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 03:30 AM
just an update,
I found a workaround for the same requirement
create a script include with the following code
var threeMonthsAgo = gs.daysAgoStart(90); // Calculate the date 90 days ago
var changedIncidents = [];
// Query the sys_audit table for changes in the priority field of incidents
var audit = new GlideRecord('sys_audit');
audit.addQuery('tablename', 'incident'); // Focus on the incident table
audit.addQuery('fieldname', 'priority'); // Focus on changes to the priority field
audit.addQuery('sys_created_on', '>=', threeMonthsAgo); // Limit to changes within the last three months
audit.query();
while (audit.next()) {
// Collect unique Sys IDs of incidents with changed priorities
var docKey = audit.documentkey.toString();
if (changedIncidents.indexOf(docKey) === -1) {
changedIncidents.push(docKey); // Store the Sys ID
}
}
return changedIncidents;
create a report on incident table
use filter condition as follows
sys_id is one of the javascript: new <scriptinludename>().<functionname>()
this will give you the incidents from last 3 months for whom priority is changed
Thank you
Mark as helpful if this helped you a little
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 03:30 AM
just an update,
I found a workaround for the same requirement
create a script include with the following code
var threeMonthsAgo = gs.daysAgoStart(90); // Calculate the date 90 days ago
var changedIncidents = [];
// Query the sys_audit table for changes in the priority field of incidents
var audit = new GlideRecord('sys_audit');
audit.addQuery('tablename', 'incident'); // Focus on the incident table
audit.addQuery('fieldname', 'priority'); // Focus on changes to the priority field
audit.addQuery('sys_created_on', '>=', threeMonthsAgo); // Limit to changes within the last three months
audit.query();
while (audit.next()) {
// Collect unique Sys IDs of incidents with changed priorities
var docKey = audit.documentkey.toString();
if (changedIncidents.indexOf(docKey) === -1) {
changedIncidents.push(docKey); // Store the Sys ID
}
}
return changedIncidents;
create a report on incident table
use filter condition as follows
sys_id is one of the javascript: new <scriptinludename>().<functionname>()
this will give you the incidents from last 3 months for whom priority is changed
Thank you
Mark as helpful if this helped you a little
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 03:43 AM
Hi @Gaurav Vaze ,
By default it will capture both on insert and onupdate.
To avoid insert values you need to create a business rule which runs on prority update which creates a record on metric defination table to track all the updates on priority.
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 03:47 AM
but looking at the script, we are only concerned about priority, right?
i tried this script in Si and updated the incidents but nothing was concernful
also creating metric instance a good idea however it is difficult for historical data to capture and the definition will also capture other incidents when created isn't it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 04:03 AM
Hi @Gaurav Vaze
Below link could be helpful :
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.