Schedule a script execution

Non-conditional and conditional scripts can be scheduled.

Procedure

  1. Navigate to System Definition > Scheduled Jobs.
  2. Click New.
  3. Select Automatically run a script of your choosing.
  4. Populate the following fields:
    Table 1. Schedule script execution
    Field Input Value
    Name A name to identify this scheduled script execution
    Active If true, the script will be executed at the scheduled date and time.
    Run The type of schedule to execute the script on. Choices are:
    • Daily
    • Weekly
    • Monthly
    • Periodically
    • Once
    Day
    • If Run is Weekly, the day of the week
    • If Run is Monthly, the day of the month.
    Repeat Interval If Run is Periodically, the duration between each script execution.
    Time If Run is Weekly or Monthly the time of day, on a 24 hour clock.
    Starting The date and time of the first scheduled script execution.
    Application The application that contains the script.)
    Conditional If checked, the entity will only be executed if certain conditions are met.
    Condition If Conditional is checked, a script determines under what conditions the scheduled script is executed. The last expression of the script should evaluate to a Boolean (true/false) value.
    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 The script to run at the scheduled date and time. For example, copy script logic from a business rule or call a script include.

Example

The following is an example of a conditional script. This example 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'