- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2012 08:06 AM
Bear with me, I'm pretty new to SN and very new to scripting. I'm pretty good at reverse engineering things but not as great at creating from scratch. After searching the forums I noticed that there didn't seem to be a way to get an aging report for incidents. (How many open are 0-2 days old, 3-7 days old, etc.)
Below is what I have tried and it's not quite working yet, anyone wanna point out where I screwed up?
I created a new field called Aging Category (u_aging_category) on the incident table.
I wrote the following script as a scheduled job:
//************************ Set Aging Category **************************************
var optime = current.opened_at.getGlideObject().getNumericValue();
var nowtime = gs.nowDateTime().getGlideObject().getNumericValue();
var totalTime = nowtime - optime ;
var calculation = totalTime/1000/60/60/24;
if (calculation <= 2){
current.u_aging_category = '0-2 Days';
}
if (calculation <= 7 && calculation > 2){
current.u_aging_category = '3-7 Days';
}
if (calculation <= 14 && calculation > 7){
current.u_aging_category = '8-14 Days';
}
if (calculation <= 21 && calculation > 14){
current.u_aging_category = '15-21 Days';
}
if (calculation <= 28 && calculation > 21){
current.u_aging_category = '22-28 Days';
}
if (calculation > 28){
current.u_aging_category = '> 28 Days';
}
In theory this should update the Aging Category field when I run the job and then I can report on it using a Pivot table. Unfortunately, the field is not updating. Any quick thoughts?
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2012 02:13 PM
I believe the problem is you are not actually querying any records, nor updating them. This is what I have done.
I have a Scheduled Job...
...that calls a function in a Script Include:
function u_updateAgingCategoryField() {
var elapsedTime = 0;
var aging = '';
var currentTimeNow = gs.nowDateTime();
var gr = new GlideRecord('incident');
gr.addEncodedQuery('u_aging_category!=>28^ORu_aging_category=');
gr.query();
while(gr.next()) {
elapsedTime = (gs.dateDiff(gr.opened_at, currentTimeNow, true)) /60/60/24;
//check to see when the item was created
if (elapsedTime <= 2) aging = '0_2';
if (elapsedTime > 2) aging = '3_7';
if (elapsedTime > 7) aging = '8_14';
if (elapsedTime > 14) aging = '15_21';
if (elapsedTime > 21) aging = '22_28';
if (elapsedTime > 28) aging = '>28';
gr.setWorkflow(false); //skip any Business Rules
gr.autoSysFields(false); //do not update system fields
gr.u_aging_category = aging;
gr.update();
}
}
Notice in the function that I am excluding incidents >28 days because we do not want to keep updating them with ">28 Days" all the time.
Now for the trick so that the Pivot Table orders the columns properly - on the Aging Category dictionary record, set the Default value to be "0_2" and the Choice field to "Dropdown without -- None --" and create some Choice entries:
Otherwise the report will sort the columns alphabetically. And so you should end up with the following report:
It is setup in https://demo23.service-now.com/ at the moment. I've also attached an update set that will re-create it for you if you do not get a change to look at demo23 today.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2016 08:25 AM
Can you send the instructions on how you created this "Workload Incident Aging (By Team)" report/chart?
Thanks,
Karl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2012 02:13 PM
I believe the problem is you are not actually querying any records, nor updating them. This is what I have done.
I have a Scheduled Job...
...that calls a function in a Script Include:
function u_updateAgingCategoryField() {
var elapsedTime = 0;
var aging = '';
var currentTimeNow = gs.nowDateTime();
var gr = new GlideRecord('incident');
gr.addEncodedQuery('u_aging_category!=>28^ORu_aging_category=');
gr.query();
while(gr.next()) {
elapsedTime = (gs.dateDiff(gr.opened_at, currentTimeNow, true)) /60/60/24;
//check to see when the item was created
if (elapsedTime <= 2) aging = '0_2';
if (elapsedTime > 2) aging = '3_7';
if (elapsedTime > 7) aging = '8_14';
if (elapsedTime > 14) aging = '15_21';
if (elapsedTime > 21) aging = '22_28';
if (elapsedTime > 28) aging = '>28';
gr.setWorkflow(false); //skip any Business Rules
gr.autoSysFields(false); //do not update system fields
gr.u_aging_category = aging;
gr.update();
}
}
Notice in the function that I am excluding incidents >28 days because we do not want to keep updating them with ">28 Days" all the time.
Now for the trick so that the Pivot Table orders the columns properly - on the Aging Category dictionary record, set the Default value to be "0_2" and the Choice field to "Dropdown without -- None --" and create some Choice entries:
Otherwise the report will sort the columns alphabetically. And so you should end up with the following report:
It is setup in https://demo23.service-now.com/ at the moment. I've also attached an update set that will re-create it for you if you do not get a change to look at demo23 today.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2012 07:27 PM
You are a rockstar. Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2013 06:51 AM
Hi JIM, Can you help me on this. I have tickets that are only one day old but they are showing as 28. Please see Attach.
Thanks in advance
text
******Scheduled Script Execution************
u_updateAgingCategoryField(); // calls script include
************ Script Include ******************
Name : u_updateAgingCategoryField
function u_updateAgingCategoryField() {
var elapsedTime = 0;
var aging = '';
var currentTimeNow = gs.nowDateTime();
var gr = new GlideRecord('incident');
gr.addEncodedQuery('u_aging_category!=>28^ORu_aging_category=');
gr.query();
while(gr.next()) {
elapsedTime = (gs.dateDiff(gr.opened_at, currentTimeNow, true)) /60/60/24;
//check to see when the item was created
if (elapsedTime <= 2) aging = '0_2';
if (elapsedTime > 2) aging = '3_7';
if (elapsedTime > 7) aging = '8_14';
if (elapsedTime > 14) aging = '15_21';
if (elapsedTime > 21) aging = '22_28';
if (elapsedTime > 28) aging = '>28';
gr.setWorkflow(false); //skip any Business Rules
gr.autoSysFields(false); //do not update system fields
gr.u_aging_category = aging;
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2013 09:48 AM
Do you have the default value for the field set to "0_2"? So when you create the Incident, it should show "0-2 Days" - is that correct?
I wonder if it is a date format issue? What is the system's default date format (System Properties \ System)?