How to write a script to show tickets created with a 5min delay or more from impaired time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 07:35 AM
Hello,
I'm trying to create a report or a widget (whichever will help me illustrate best) tickets which are created with more than 5 mins delay from the actual impaired time.
I'm assuming the best way to achieve this will be in PA with a script, and have never written a script yet.
Is anyone able to please help me?
Thanks!
- Labels:
-
Performance Analytics

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 09:08 PM
Hi
Yes, it would help as it could be checked if duration is greater than the threshold.
Alternatively, writing a Business Rule that would run upon insert, perform the calculation (created time - impaired time), and attach a tag (which can be pre-created) to the incident in case the duration value is greater than threshold is another option. A report on incident table filtered by the tag can then be created. This might be a better approach than metrics.
Information on tags - https://docs.servicenow.com/en-US/bundle/sandiego-platform-user-interface/page/use/common-ui-elements/concept/c_Tags.html
Had the threshold been in hours instead of minutes, one could directly run a report on incident table to achieve this with a filter like the one below ("Updated" to be replaced with "Service impaired" field)
Hope all of these have helped in some way.
Thanks,
Arav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 08:36 AM
Hello
good that you are following PA as an approach in your PA script you can write like this
Give the aggregate as count distinct and select Script option and tag your script .
And in fields you can give your two date fields impaired time and created on
You script can be like
Replace you impaired time field name in below script
getImpairedTime();
function getImpairedTime()
{
var imp = current.u_impaired _time.getGlideObject();
var added =imp.addSeconds(600);
var gr= new GlideRecord('your table');
gr.addQuery('sys_created_by','>',added);
gr.query();
return gr.getRowCount();
}
PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 09:11 AM
Arav probably has the best answer to this, I'll just chime in with a couple of thoughts:
- Using a Metric definition to do it will save you having to create a new custom field on the incident/task table just to hold the "true false" or "minutes delay from impaired time" depending on whether you want just a true false or the actual count (actual count is better IMO, because then you can look at HOW much delay there was and sort by it).
- Performance Analytics for this would be good if you're wanting to generally see percents and counts of how many tickets were created with more than 5 minutes delay, but it's less useful if you want to see SPECIFIC tickets with a 5 minutes delay. It depends on the snapshots, which are limited to about 5000 records. That may still be enough depending on how many tickets a day meet the criteria, but it's better suited towards long term trending, forecasting, and analysis than specific single record activities.
- If you DO want to use Performance Analytics for those things, the easiest way is probably STILL to use a Metric Definition to count the time difference for each ticket. There's already a 'Database View' called "Incident Metric" that combines the metrics measured on the incident table with the incidents themselves, so instead of having to build a more complex script to pull it in to Performance Analytics, you can just have Performance Analytics use Incident Metric as a source and now your criteria is just "Metric Definition is '<whatever metric name is>' & Value > 5 minutes, and it'll pull all those same records in. The drilldown is still into the Incident table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 08:13 AM
Crafting exceptional nursing essays requires a unique blend of medical expertise and impeccable writing skills. Our nursing essay writing service brings together professionals from both realms, ensuring that your essays not only convey accurate healthcare insights but also do so with clarity, precision, and eloquence. Say goodbye to the stress of juggling nursing assignments and demanding clinical responsibilities. Our nursing essay service on https://www.nursingpaper.com/nursing-term-paper/ offers you a secret weapon – a team of seasoned writers who specialize in nursing topics. Enjoy the peace of mind that comes from knowing your essays are in capable hands.