Scheduled Script API - ServiceNow Fluent

  • Freigeben Version: Australia
  • Aktualisiert 12. März 2026
  • 5 Minuten Lesedauer
  • The Scheduled Script API defines scheduled script executions [sysauto_script] that run at a specific time or on a recurring basis. Scheduled script executions are also referred to as scheduled jobs.

    For general information about scheduled script executions, see Scheduled jobs.

    ScheduledScript object

    Create a scheduled script execution [sysauto_script] to define a server-side script that runs on a schedule.

    Tabelle : 1. Properties
    Name Type Description
    $id String or Number Required. A unique ID for the metadata object. When you build the application, this ID is hashed into a unique sys_id. For more information, see ServiceNow Fluent language constructs.

    Format: Now.ID['String' or Number]

    name String Required. The name of the scheduled script.
    active Boolean Required. Flag that indicates whether the scheduled script is enabled.
    Valid values:
    • true: The scheduled script executes on the specified schedule.
    • false: The scheduled script doesn't execute.

    Default: true

    script Script Required. A server-side script that runs on a schedule. This property supports a function from a JavaScript module, a reference to another file in the application that contains a script, or inline JavaScript.
    Format:
    • For functions, use the name of a function, function expression, or default function exported from a JavaScript module and import it into the .now.ts file. For information about JavaScript modules, see JavaScript modules and third-party libraries.
    • To use text content from another file, refer to a file in the application using the following format: Now.include('path/to/file'). For more information, see ServiceNow Fluent language constructs.
    • To provide an inline script, use string literals or template literals for multiple lines of code: 'Script' or `Script`.
    condition String A JavaScript conditional statement that specifies the fields and values that must be true for the script to run. This property supports a function from a JavaScript module, a reference to another file in the application that contains a script, or inline JavaScript. The script must return a Boolean value, which executes the scheduled script when true.
    Warnung:
    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.

    Format:
    • For functions, use the name of a function, function expression, or default function exported from a JavaScript module and import it into the .now.ts file. For information about JavaScript modules, see JavaScript modules and third-party libraries.
    • To use text content from another file, refer to a file in the application using the following format: Now.include('path/to/file'). For more information, see ServiceNow Fluent language constructs.
    • To provide an inline script, use string literals or template literals for multiple lines of code: 'Script' or `Script`.
    runType String The time interval to use for running the scheduled script.
    Valid values:
    • daily: Runs daily at a designated time.
    • weekly: Runs on a weekly basis at a designated time and day of the week.
    • monthly: Runs on a monthly basis at a designated time and day of the month.
    • once: Runs for a single occurrence only.
    • periodically: Runs on a designated repeating interval.
    • on_demand: Runs on demand when a user selects Execute Now from the scheduled script record.
    • business_calendar_start: Runs on the starting entry dates for the business calendar that you specify with the businessCalendar property. A scheduled script runs for the starting date of each of the business entries that you defined for the business calendar. 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.
    • business_calendar_end: Runs for the ending date for the business calendar that you specify with the businessCalendar property. This selection runs in the same manner as business_calendar_start, but for the end dates of the associated business calendar entries.
      Hinweis:
      If you specify business_calendar_start or business_calendar_end, you can apply an offset factor to schedule the script to run before or after the time span of the selected business calendar. To learn more about creating and using business calendars and defining business calendar entries, see Creating business calendars and Define business calendar entries.
    runTime Object Required if the runType property is daily, weekly, monthly, once, or periodically. The time of day on a 24-hour clock and the time zone on which the scheduled job runs.

    The default time zone is Coordinated Universal Time (UTC).

    runTime: {
      year: Number,
      month: Number,
      day: Number,
      hour: Number,
      minute: Number,
      second: Number,
      timeZone: 'String'
    }
    Valid values for timeZone:
    • Canada/Atlantic
    • Canada/Central
    • Canada/Eastern
    • Canada/Mountain
    • Canada/Pacific
    • Europe/Amsterdam
    • Europe/Berlin
    • Europe/Brussels
    • Europe/Dublin
    • Europe/London
    • Europe/Madrid
    • Europe/Paris
    • Europe/Rome
    • Europe/Stockholm
    • Europe/Zurich
    • floating
    • GMT
    • Hongkong
    • US/Arizona
    • US/Central
    • US/Eastern
    • US/Hawaii
    • US/Mountain
    • US/Pacific

    Default: 00:00:00

    runDayOfWeek String Required if the runType property is weekly. The day of the week on which the scheduled script runs.
    Valid values:
    • monday
    • tuesday
    • wednesday
    • thursday
    • friday
    • saturday
    • sunday
    runDayOfMonth Number Required if the runType property is monthly. The day of the month on which the scheduled script runs.

    Minimum value: 1

    Maximum value: 31

    runPeriod Object Required if the runType property is periodically. The designated repeating interval on which the scheduled script runs. At least one of the properties must have a non-zero value.
    runPeriod: {
      days: Number,
      hours: Number,
      minutes: Number,
      seconds: Number,        
    }
    businessCalendar String Required if the runType property is business_calendar_start or business_calendar_end. The sys_id of a business calendar [business_calendar] that is used to determine a start date or end date for the scheduled script.
    $meta Object Metadata for the application metadata.
    With the installMethod property, you can map the application metadata to an output directory that loads only in specific circumstances.
    $meta: {
          installMethod: 'String'
    }
    Valid values for installMethod:
    • demo: Outputs the application metadata to the metadata/unload.demo directory to be installed with the application when the Load demo data option is selected.
    • first install: Outputs the application metadata to the metadata/unload directory to be installed only the first time an application is installed on an instance.
    $override Object Fields and their values provided to configure fields that aren't included in a ServiceNow Fluent API or to override an existing field.
    Warnung:
    Type safety isn't enforced for fields configured with the $override property.
    $override: {
     field: value, 
     ...
    }

    In the following example, the script runs daily at 12 p.m. if a user has the admin role.

    import { ScheduledScript } from '@servicenow/sdk/core';
    import { dailyJob } from '../server/scripts.js'
                
    ScheduledScript({
        $id: Now.ID['daily_scheduled_script'],
        name: 'daily_scheduled_script',
        active: true,
        condition: 'gs.getUser().hasAssignedRole("admin");',
        runType: 'daily',
        runTime: {
            hour: 12
        },
        script: dailyJob,     
    })