Useful scheduling scripts
-
- UpdatedFeb 1, 2024
- 5 minutes to read
- Vancouver
- Building applications
A business rule script specifies the actions that the business rule takes. Scripts commonly include predefined global variables to reference items in your system, such as the current record. Global variables are available to all business rules.
Calculate duration given a schedule
Type: Before update/insert business rule.
Description: A business duration calculates the open to close duration on an incident based on the particular Creating and using schedules. If there is no schedule specified, the script will simply use the first schedule returned by the query.
Script example:
Check upcoming termination dates
Type: Scheduled script.
Description: This script checks nightly for termination dates on contracts coming up in 90, 50, or 10 days (depending on the contract duration field).
Script example:
- Comparing two date fields.
- Parsing XML payloads.
- Aborting a database action in a business rule.
- Specify the operation that triggers the business rule.
- Use the scratchpad with display business rules to change form values just before a user loads the form.
- Use the OR condition like you would in a condition builder.
You can also utilize the system's scripting functionality available for server-side scripts.
You can use options on the Business Rules form to build conditions, set field values, and display alert messages without needing to write a script.
Abort a database action in a business rule
During a before business rule script, you can cancel or abort the current database action using the current.setAbortAction(true) method.
For example, if the before business rule is executed during an insert action, and you have a condition in the script that calls current.setAbortAction(true), the new record stored in current is not created in the database.
Add autofill functionality
Add autofill functionality is also called incident template, auto assignments, quick calls, call script, or auto populate.
Let's say you want to auto-fill your Short Description based on the Subcategory selected. First, create a lookup table, then populate the key field, in this case Subcategory and the auto-filled field, Short Description. So let's say your table had a record with Subcategory = Password and Short Description = Password Reset. When the user selects the subcategory of Password on the Incident form a client script looks up the matching record and sets short description equal to Password Reset. Client script settings... Type = onChange, Table name = incident, Field name = Subcategory.
You could populate many fields or even pull in call script questions into the Comments field so call center personnel gather good information to pass on to a technician. There are already Assignment Rule, Templates and Wizards built in that perform similiar functions.
Example script: A default before-query business rule
You can use a query business rule that executes before the database query is made to prevent users from accessing certain records.
Consider the following example from a default business rule that limits access to incident records.
Name | Table | When |
---|---|---|
incident query | Incident | before, query |
Example script
Schedule script for weekdays
Type: Business Rules/Client Scripts
Set date field according to current date
To validate the input of all date/time fields, you can use the following in a validation script (
). Because the date/time format is hard coded in this script, it must match your instance's date/time format. If your instance's date/time format changes, you must update your validation script.