Scripting in Performance Analytics
-
- UpdatedJan 30, 2025
- 4 minutes to read
- Yokohama
- Performance Analytics
Performance Analytics provides several script objects for use in scripts and APIs for querying Performance Analytics data. The scripts serve as breakdown mappings or to calculate a value from an indicator.
Tips on scripts
- In general, use scripts only to support indicators like Age with date processing, using the
score_start
andscore_end
variables. - Limit unnecessary fields. Every time you include an extra dot-walked field, you add an extra join to the query.
- Try to replace manual breakdowns with database views for better performance.
- Try to use script includes for common functions. For more information, see Script includes.
- If the data is not structured in a way you need for reporting, try adding 'reporting fields' to the operational tables instead of creating scripts. For more information, see this Community post.
- If you are running a background script that queries the Performance Analytics scores or snapshots tables, you cannot access data about a scoped application unless you have an appropriate role for that application.
Breakdown mapping and indicator scripts
A breakdown mapping script typically returns either a sys_id of a breakdown element or an integer to put the score in a bucket. Indicator scripts return a score calculated from one or more fields. The same script can serve both as a breakdown mapping script and as an indicator script.
Example: Breakdown script
For example, consider the provided Incident.Age.Days script, which uses the opened_at
field from the incident table. This script serves as a breakdown mapping for the Age breakdown, which uses the Incident Age
Ranges (Days) bucket group as the breakdown source.
In this example, current.opened_at
gets the timestamp of when the currently evaluated record was opened. The score_end
script variable comes from the data collector and is bound to the period being collected. For example, if a monthly indicator is being collected, the score_end
is the end of the month. Here the
timestamp of when the incident was opened is subtracted from the timestamp of the end of the collection period and the result is converted to days.
This example includes the Incident.opened_at
field, which is specified in the
Fields field for this script. You can use score_start
and score_end
without defining them in the Fields
field.
Create a script in Performance Analytics
To create a script, first select the facts table to which the script applies and explicitly select any fields.
Before you begin
Procedure
What to do next
Performance Analytics variables
Several variables are available for use in Performance Analytics scripts and formula indicators.
You can use the following variables in Performance Analytics scripts and formulas.
score_start
: First second of the day of the first indicator score collection. For scripts, the time is calculated based on the difference between the time zone of the Run As user for the collection job and the database time zone, which is GMT. For formulas, the time is calculated based on the difference between the time zone of the user who executes the formula and GMT. A user executes a formula by viewing the formula indicator in a dashboard widget or on the Analytics Hub.score_end
: Last second of the day of the last indicator score collection. The time is calculated the same way as forscore_start
.pa
: A formula variable, not usable in scripts, that provides a set of Analytics Hub attributes and methods.
In scripts, the score collection start and end variables are
GlideElementGlideObject objects. You can obtain a
GlideDateTime object from these variables by calling
getGlideObject(), such as in this example: gs.log("Score main =
" + score_end.getGlideObject().getDayOfWeek());
In formulas, the score collection start and end variables already are
GlideDateTime objects. Therefore, you can use the variables directly
without calling getGlideObject(), such as in this example:
gs.log("Score main = " + score_end.getDayOfWeek());
The values of the start and end variables are bound to the period being collected. For
example, if a monthly indicator is being collected, the score_end
is the
end of the month.
The score_start
and score_end
values are calculated based
on the time zone of the relevant user. For Performance Analytics scripts, this is the Run As
time zone for the collection job. For formulas, this is the time zone of the user who views
the formula indicator in a dashboard widget or the Analytics Hub. Users in
different time zones therefore may have different dates for score_start
and
score_end
in a formula.
On this page
Related Content
- Create a breakdown mapping on a breakdown record
Specify which field on the indicator source references the breakdown source. If no appropriate field is available, specify a script to query the indicator source.
- Server Scoped API List
- GlideDateTime - Scoped
- Get analytics methods in formulas
To insert a calculated value from the Analytics Hub into a formula, use a method in the formula.
- Changes to score_start/end because of different user time zones
For formula indicators, the values of the variables score_start and score_end are calculated based on the time zone of the user who is executing the formula. If users in different time zones execute the same formula, the values of score_start and score_end change.