- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 02:54 PM
Script I have:
var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};
var mins=function(x,y){return diff(x,y)/(24*60*1000);};
mins(current.opened_at, current.now);
I need something to replace the now that will give me the time difference from the current date time when the job is ran.
It will be used as part of a breakdown in conjunction with a bucket group if that matters. The script works above for age, but requires another field in that table to
do the calculation like current.closed_at.
Solved! Go to Solution.
- Labels:
-
Performance Analytics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2017 11:32 AM
You can use a GlideDateTime object
var diff=function(x){
var y = new GlideDateTime();
return y.getNumericValue() - x.dateNumericValue();
};
var mins=function(x){return diff(x)/(60*1000);};
mins(score_start.opened_at);
Be aware that PA is not really intended to run jobs every minute.
If you explain your requirement a bit more, maybe there is a better solution...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 03:06 PM
Have you looked at Performance Analytics script variables
I recommend using the score_end variable. This gives the end of day for each day you collect.
So when you collect for a older day it will be set to 23:59:59 of that day.
This is probably the result you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2017 11:13 AM
The problem is I need now, not end of day. I will be running this indicator every min or two in a job. It will be used to show the max wait time for our chat queue. The problem we have now with our current instance, is we can only get average wait. However, that never tells us just how long any one person is currently waiting. Sure a regular report could show us the date it came in and the analyst can do the math themselves, but we want something automated.
If there is somewhere to use the
I think that would be the answer.
Something like the below does not work.
var diff=function(x,y){return y.dateNumericValue() - x.getGlideObject().getDisplayValue().dateNumericValue();};
var mins=function(x,y){return diff(x,y)/(60*1000);};
mins(score_start.opened_at, score_end);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2017 11:32 AM
You can use a GlideDateTime object
var diff=function(x){
var y = new GlideDateTime();
return y.getNumericValue() - x.dateNumericValue();
};
var mins=function(x){return diff(x)/(60*1000);};
mins(score_start.opened_at);
Be aware that PA is not really intended to run jobs every minute.
If you explain your requirement a bit more, maybe there is a better solution...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2017 12:04 PM
I did need to fix something in script. It had incorrectly said "score_start" before.
var diff=function(x){
var y = new GlideDateTime();
return y.dateNumericValue() - x.dateNumericValue();
};
var mins=function(x){return diff(x)/(60*1000);};
mins(current.opened_at);
I get this error when using this.
Error during JavaScript evaluation com.snc.pa.dc.ScriptException: JavaScript evaluation returned: NaN in script: var diff=function(x){
var y = new GlideDateTime();
return y.dateNumericValue() - x.dateNumericValue();
};
var mins=function(x){return diff(x)/(60*1000);};
mins(current.opened_at);
at com.snc.pa.dc.Script.handleException(Script.java:216)
at com.snc.pa.dc.Script.evaluate(Script.java:179)
at com.snc.pa.dc.Script.evaluate(Script.java:156)
at com.snc.pa.dc.DataCollector.collect(DataCollector.java:234)
at com.snc.pa.dc.DataCollector.collect(DataCollector.java:188)
at com.snc.pa.dc.DataCollector.collect(DataCollector.java:144)
at com.snc.pa.dc.DataCollectorJob.collect(DataCollectorJob.java:158)
at com.snc.pa.dc.DataCollectorJob.collectWithMutex(DataCollectorJob.java:94)
at com.snc.pa.dc.DataCollectorJob.execute(DataCollectorJob.java:80)
at com.glide.schedule.JobExecutor.execute(JobExecutor.java:83)
at com.glide.schedule.GlideScheduleWorker.executeJob(GlideScheduleWorker.java:204)
at com.glide.schedule.GlideScheduleWorker.process(GlideScheduleWorker.java:142)
at com.glide.schedule.GlideScheduleWorker.run(GlideScheduleWorker.java:59)
Caused by: java.lang.Exception: JavaScript evaluation returned: NaN
... 12 more
I also get a warning that I did not before.
No data was collected between 07-16-2017 and 07-16-2017 for indicator source "SD Chat.Queue.Entry". Data within this range is older than the maximum age, based on indicator frequency and collection periods, for all indicators associated with this indicator source.