Automatically run a script of your choosing
Schedule both conditional and non-conditional scripts. If Domain Separation is installed in the instance, you can also select, filter, sort, and schedule scripts based on their assigned domains.
Before you begin
Roles required: system_scheduler_admin
About this task
The following is an example of a conditional script. It runs the scheduled job only if there are active incidents older than 30 days.
// Only run this Scheduled Job if there are active Incidents over 30 days old
var ga = new GlideAggregate('incident');
ga.addAggregate('COUNT');
ga.addQuery('active', 'true');
ga.addQuery('sys_created_on', '<', gs.daysAgo(30));
ga.query();
ga.next();
ga.getAggregate('COUNT') !== '0'
Procedure
Navigate to All > System Definition > Scheduled Jobs.
Select New.
Select Automatically run a script of your choosing.
On the form, fill in the fields.
| Field | Description |
|---|---|
| Name | Name that identifies this scheduled job. |
| Active | Option that indicates that scheduled job is active and should be executed at the specified date and time. |
| Application | Name of the application that contains the script. Global appears if the script is in the global scope. |
| Conditional | Option for enabling the running of the scheduled job if certain conditions are met in the associated script. |
| Condition | A conditional script that determines if a scheduled job should run. The last expression of the script should evaluate to a Boolean (true/false) value. This text box appears only if you select Use conditions. Warning: Conditional scripts for scheduled report emails and Performance Analytics data collection jobs are executed in the sandbox. Therefore, function definitions are not allowed. Some API calls and keywords are also not allowed.For more information, see Script sandbox evaluator. After upgrade, jobs with conditional scripts that contain these disallowed API components finish with errors. |
| Run | Time interval to use for running the scheduled job:
For example, if the business calendar represents a fiscal year, and the starting date of each entry is a fiscal month, the scheduled job runs on the first day of each month.
Note: When you select Business Calendar: Entry Start or Business Calendar: Entry End, you can apply an offset factor to schedule the job to run before or after the time span of the selected business calendar. If you select a business calendar and all its business calendar spans are in the past, the job would never run since that is an invalid configuration. To learn more, see the Offset type and Offset fields. To learn more about creating and using business calendars and defining business calendar entries, see Creating business calendars and Define business calendar entries. |
| Day | Day on which the scheduled job should run.
|
| Repeat Interval | Duration of the repeat interval for each scheduled job execution. Enter the duration in the number of days, hours, or minutes. For example:
|
| Time zone | Time zone to use with the Time field entry when you specify the time at which the scheduled job should run. Select a time zone entry:
For example, the scheduled job runs at 04:45 p.m. US/Pacific time if it’s the user's assigned time zone, and you enter
For example, the scheduled job runs at 10:15 p.m. London time if Europe/London is the default system time zone for the instance, and you enter
For example, the scheduled job runs at 1:30 p.m. in the US Eastern time zone if you select US/Eastern, and enter |
| Time | Time of day at which the scheduled job should run, expressed in hours, minutes, and seconds on a 24-hour clock. The selection that you make in the Time zone field determines the time zone for this entry. |
| Day | Day on which the scheduled job should run.
|
| Repeat Interval | Duration of the repeat interval for each scheduled job execution. Enter the duration in the number of days, hours, or minutes. For example:
|
| Starting | Allows you to define the beginning window of time when you would like your job to start running. The job will actually run at the time specified in Run time. Select the calendar date and time. The Starting field appears only if you select one of the following Run types in the Run field:- Daily - Day and Month in Year - Day in Week in Month in Year - Monthly - Once - Periodically - Week in Month - Weekly For the run type Periodically, the Starting time is the date and time of the first scheduled job generation. |
| Business Calendar | Business calendar entry that you’re using to determine the business calendar start or end date for the scheduled job. This field appears only if you select Business Entry: Start Date or Business Entry: End Date in the Time field. |
| Run as \[Optional\] | Select another user to run the script execution as. Configure the form to add this field if it is not present. |
| Run this script | Name of the script to run at the scheduled date and time. For example, copy script logic from a business rule, or call a script include. |
If Domain Separation is installed in this instance, the following fields also appear for selecting, sorting, and scheduling jobs by domain.
Note: The Domain Support - Domain Extensions Installer plugin installs these fields. To learn more, see Request domain separation.
| Field | Description |
|---|---|
| Domain iterator | Check box that enables this job to run across multiple domains. If selected, the Domain source table and Domain source filter fields appear. |
| Domain source table | Name of the domain-separated table that is the source of the domains in which the scheduled job should run. For example, select Department (cmn_department) if you want to use it as the source of the assigned domains used to schedule scripts. The scheduled job determines these domains from the sys_domain field of the source table records. To learn more, see Domain assignment. Note: It's a good idea to create a domain-separated table solely dedicated to sourcing domains, unless you have a use case that warrants using an existing one. If you do create a new one, simply select it using this field. |
| Domain source filter | Optional condition you can specify to filter the records queried from the selected domain source table. 1. Select the field to use for filtering records. 2. Add filtering conditions and operators to narrow the domain selection criteria. To learn more, see Filters. |
The following processing takes place when scheduling a job in a domain-separated instance:
- It first queries the selected domain source table.
- If you specified a condition in the **Domain source filter** field, it applies the filtering condition to narrow down the resulting set of records.
- Finally, it retrieves its list of unique domains from the sys\_domain columns of these records.
- Select Update to update the scheduled job, Execute Now to execute the scheduled script immediately, or Delete to delete the job.
Parent Topic:Create a scheduled job
Related topics
Advanced options for scheduled jobs
Enable run types for scheduled job child tables