Scripts
At its most basic, scripts are code designed to perform a task or specific task. The scripts in the Civic Platform are written in JavaScript, a programming language which conforms to the ECMAScript standard.
Scripts can be simple, such as a single statement, or complex, such as a library of functions and statements for an interface.
In the Civic Platform, scripts can be classified as the following types or categories of scripts:
-
Master Scripts
-
Custom business rules scripts for events and non-events
-
Configurable standard scripts
Event Master Scripts build the environment for the associated event, load the master script libraries, and then execute the scripts associated (see Event execution for more information). The master scripts are built into the Civic Platform (if the Civic Platform is configured to use the built in scripts, which is the default configuration) and cannot be edited. When an event master script is associated to an event, it will not change the version of the script associated to the event even after the Civic Platform is updated to a new version.
When you create a script and load it into the Civic Platform, you have created a custom business rules script. These script enhance the functionality of the Civic Platform and enforce your agency’s specific business rules and requirements.
The master script uses the event prefix and the record type mask you which you named the script to determine whether or not to execute the script. The naming convention for event custom business rules scripts is <event prefix>:<record type mask> where the record type mask is the four part record type identifier: <group>/<type>/<subtype>/<category> with wild cards used to allow one script to match multiple record types.
Examples:
-
A custom business rule script named
ASA:Building/Residential/Electrical/*would execute on the ApplicationSubmitAfter (ASA) event for all records in the Building module with record type of ‘Residential’ and a subtype of ‘Electrical’ regardless of the category.
-
A custom business rule script named
PRA:*/*/*/*would execute on the PaymentReceiveAfter (PRA) event for all record types.
Other types of custom business rules scripts are batch jobs, page flow scripts (for ACA), set scripts, expressions, and agency specific script libraries. These non-event scripts don’t have to have a specific naming convention but we highly recommend setting standards for naming and script organization so these scripts are easier to maintain.
Two of the non-event custom business rules scripts which are regularly used are the INCLUDES_CUSTOM and the INCLUDES_CUSTOM_GLOBALS scripts.
The INCLUDES_CUSTOM_GLOBALS script contains any statements which should execute for every event, such as to set up users who will see the debug output of scripts automatically or any other globally needed functionality. This script is agency specific and is not required for scripting to function.
The INCLUDES_CUSTOM script contains custom functions and statements which will load after all other Civic Platform libraries or statements but before the custom business rules scripts. This lets an agency develop functionality which is agency specific and, again, is optional and not required for scripting to function. If you are using a repository to store and manage scripts, the INCLUDES_CUSTOM script is built from the matching folder in the repository where the files with the individual functions and statements are stored.
Each master script associated with an event will load these master script libraries:
INCLUDES_ACCELA_FUNCTIONSINCLUDES_ACCELA_GLOBALS
The INCLUDES_ACCELA_FUNCTIONS is a library of JavaScript functions developed and maintained by Accela which make using the EMSE API easier to use or are commonly utilized functionality.
The INCLUDES_ACCELA_GLOBALS is a set of statements to load commonly used data into variables for easier use, such as the Cap object, CapId object, custom fields, custom tables, et cetera. After the INCLUDES_ACCELA_GLOBALS script executes it calls the INCLUDES_CUSTOM_GLOBALS script to load any agency specific custom statements.
The Civic Platform Configurable Business Rules Engine is an EMSE master script function designed to reduce the amount of custom scripting with standard functionality defined in Business Rules configuration files. This new functionality to the Civic Platform allows you to automate with a great deal of flexibility in criteria and actions.