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: 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

  1. Navigate to All > System Definition > Scheduled Jobs.
  2. Select New.
  3. Select Automatically run a script of your choosing.
  4. On the form, fill in the fields.
  5. 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.
  6. Click Update to update the scheduled job, Execute Now to execute the scheduled script immediately, or Delete to delete the job.