- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 01:21 PM
Is there some documentation on how to write scripts in Performance Analytics, meaning the language, functions, syntax, etc.? All I can find is the following, which presents the concept and a small example but doesn't tell me how to write them:
https://docs.servicenow.com/bundle/kingston-performance-analytics-and-reporting/page/use/performance-analytics/concept/pa-scripts.html#pa-scripts
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 09:05 PM
Scripts used for indicators, need to return a numeric value if you want to SUM or AVG. For a COUNT of COUNT DISTINCT, you can return any scalar. For a script used in a breakdown mapping, you must return a sys id (or array of sys_ids) that correspond to the breakdown source.
You have two very special variables, score_start and score_end which are when the period you are looking at started (for example a monthly indicator would have the first of the month and midnight as score_start and score_end would be the last second of the last day of the month).
That is it, everything else is standard ServiceNow scripting with access to the entire platform. It is an amazingly flexible platform.
That being said, the best script is no script. Any script you reference should use score_start or score_end (the very special Performance Analytics variables) otherwise you are masking a data model problem more often than not. I recommend giving this article a read to better understand why this is: https://community.servicenow.com/community?id=community_blog&sys_id=2f99990fdbee5b00fece0b55ca9619fb
It is better to fix the root issues with the data model rather than "fix" it in Performance Analytics.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 01:38 PM
Hi Casey,
in addition to the documentation that you mentioned, the best content for learning about scripting in Performance Analytics is the following (search in Scoped area for GlideDateTime):
You will find examples for each methods.
Hope this will be helpful for your need.
Please, remember to mark Correct or Helpful if you find my response useful.
Cheers
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2018 09:05 PM
Scripts used for indicators, need to return a numeric value if you want to SUM or AVG. For a COUNT of COUNT DISTINCT, you can return any scalar. For a script used in a breakdown mapping, you must return a sys id (or array of sys_ids) that correspond to the breakdown source.
You have two very special variables, score_start and score_end which are when the period you are looking at started (for example a monthly indicator would have the first of the month and midnight as score_start and score_end would be the last second of the last day of the month).
That is it, everything else is standard ServiceNow scripting with access to the entire platform. It is an amazingly flexible platform.
That being said, the best script is no script. Any script you reference should use score_start or score_end (the very special Performance Analytics variables) otherwise you are masking a data model problem more often than not. I recommend giving this article a read to better understand why this is: https://community.servicenow.com/community?id=community_blog&sys_id=2f99990fdbee5b00fece0b55ca9619fb
It is better to fix the root issues with the data model rather than "fix" it in Performance Analytics.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 10:56 AM
Hello Adam,
Can you help me with below script on how to return Average value below..?
************************************************
var aSUM,rAvg;
var ga = new GlideAggregate('u_request_survey_results');
ga.addAggregate("SUM",'actual_value');
ga.groupBy("req_number");
ga.query();
while (ga.next()){
asum = ga.addAggregate("SUM",'actual_value');
rAvg = asum/3;
return rAvg;
}
************************************************