Product documentation Docs
    • English
    • Deutsch
    • 日本語
    • 한국어
    • Français
  • More Sites
    • Now Community
    • Developer Site
    • Knowledge Base
    • Product Information
    • ServiceNow.com
    • Training
    • Customer Success Center
    • ServiceNow Support Videos
  • Log in

Product documentation

  • Home
How search works:
  • Punctuation and capital letters are ignored
  • Special characters like underscores (_) are removed
  • Known synonyms are applied
  • The most relevant topics (based on weighting and matching to search terms) are listed first in search results
Topics are ranked in search results by how closely they match your search terms
  • A match on the entire phrase you typed
  • A match on part of the phrase you typed
  • A match on ALL of the terms in the phrase you typed
  • A match on ANY of the terms in the phrase you typed

Note: Matches in titles are always highly ranked.

  • Release version
    Table of Contents
    • Now Platform administration
Table of Contents
Choose your release version
    Home Orlando Now Platform Administration Now Platform administration Time configuration System scheduler Scheduled jobs Create a scheduled job Automatically run a script of your choosing

    Automatically run a script of your choosing

    • Save as PDF Selected topic Topic & subtopics All topics in contents
    • Unsubscribe Log in to subscribe to topics and get notified when content changes.
    • Share this page

    Automatically run a script of your choosing

    Schedule both conditional and non-conditional scripts.

    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 System Definition > Scheduled Jobs.
    2. Click New.
    3. Select Automatically run a script of your choosing.
    4. On the form, fill in the fields.
      Table 1. Schedule script execution
      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 schedule job if certain conditions are met in the associated script.
      Condition 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 Conditional.
      Run
      Time interval to use for running the scheduled job:
      • 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.
      • Periodically: Runs on a designated repeating interval.
      • Once: Runs for a single occurrence only.
      • On Demand: Runs immediately on demand.
      • Business Calendar: Entry Start: Runs on the starting entry dates for the business calendar you select in the Business Calendar field. A scheduled job runs for the starting date of each of the business entries 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: Entry End: Runs for the ending date for the business calendar you select in the Business Calendar field. This selection runs in the same manner as Business Calendar: Entry Start, but for end dates of associated business calendar entries.
      Day
      Day on which the scheduled job should run.
      • If Run is set to Weekly, select the day of the week. For example, select Wednesday.
      • If Run is set to Monthly, select the day of the month. For example, select 25 for the 25th day of the month.
      This field only appears if you select Monthly or Weekly in the Run field.
      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:
      • To run the scheduled job every four days, enter 04 into the Days field.
      • To run it every 26 hours, enter 26 into the Hours field.
      • If it should repeat at an interval of 13:30:25, enter 13 into the Hours field, then 30 and 25 into the two unlabeled fields after it.
      Time zone
      Time zone to use with the Time field entry when you specify the time at which the scheduled job run. Select a time zone entry:
      • -None-: Use the default time zone for the logged in user who is creating the scheduled job.

        For example, the scheduled job runs at 04:45 p.m. US/Pacific time if it is the user's assigned time zone, and you enter 16:45 into the Time field.

      • Use System Time Zone: Use the default system time zone specified for the instance in which it runs.

        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 22:15 into the Time field.

      • Actual time zone.

        For example, the scheduled job runs at 1:30 p.m. in the US Eastern time zone if you select US/Eastern, and enter 13:30 into the Time field.

      Time Time of day at which the scheduled job should run, expressed in hours, minutes, and seconds on a 24-hour clock. The selection you make in the Time zone field determines the time zone for this entry.
      Starting Date and time of the first scheduled job generation. Select the calendar date and time. This field only appears if you select Periodically in the Run 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.
    Related tasks
    • Create a scheduled job
    • Personalize the system date format
    • Set a system time zone

    Tags:

    Feedback
    On this page

    Previous topic

    Next topic

    • Contact Us
    • Careers
    • Terms of Use
    • Privacy Statement
    • Sitemap
    • © ServiceNow. All rights reserved.

    Release version
    Choose your release version

      Automatically run a script of your choosing

      • Save as PDF Selected topic Topic & subtopics All topics in contents
      • Unsubscribe Log in to subscribe to topics and get notified when content changes.
      • Share this page

      Automatically run a script of your choosing

      Schedule both conditional and non-conditional scripts.

      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 System Definition > Scheduled Jobs.
      2. Click New.
      3. Select Automatically run a script of your choosing.
      4. On the form, fill in the fields.
        Table 1. Schedule script execution
        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 schedule job if certain conditions are met in the associated script.
        Condition 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 Conditional.
        Run
        Time interval to use for running the scheduled job:
        • 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.
        • Periodically: Runs on a designated repeating interval.
        • Once: Runs for a single occurrence only.
        • On Demand: Runs immediately on demand.
        • Business Calendar: Entry Start: Runs on the starting entry dates for the business calendar you select in the Business Calendar field. A scheduled job runs for the starting date of each of the business entries 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: Entry End: Runs for the ending date for the business calendar you select in the Business Calendar field. This selection runs in the same manner as Business Calendar: Entry Start, but for end dates of associated business calendar entries.
        Day
        Day on which the scheduled job should run.
        • If Run is set to Weekly, select the day of the week. For example, select Wednesday.
        • If Run is set to Monthly, select the day of the month. For example, select 25 for the 25th day of the month.
        This field only appears if you select Monthly or Weekly in the Run field.
        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:
        • To run the scheduled job every four days, enter 04 into the Days field.
        • To run it every 26 hours, enter 26 into the Hours field.
        • If it should repeat at an interval of 13:30:25, enter 13 into the Hours field, then 30 and 25 into the two unlabeled fields after it.
        Time zone
        Time zone to use with the Time field entry when you specify the time at which the scheduled job run. Select a time zone entry:
        • -None-: Use the default time zone for the logged in user who is creating the scheduled job.

          For example, the scheduled job runs at 04:45 p.m. US/Pacific time if it is the user's assigned time zone, and you enter 16:45 into the Time field.

        • Use System Time Zone: Use the default system time zone specified for the instance in which it runs.

          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 22:15 into the Time field.

        • Actual time zone.

          For example, the scheduled job runs at 1:30 p.m. in the US Eastern time zone if you select US/Eastern, and enter 13:30 into the Time field.

        Time Time of day at which the scheduled job should run, expressed in hours, minutes, and seconds on a 24-hour clock. The selection you make in the Time zone field determines the time zone for this entry.
        Starting Date and time of the first scheduled job generation. Select the calendar date and time. This field only appears if you select Periodically in the Run 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.
      Related tasks
      • Create a scheduled job
      • Personalize the system date format
      • Set a system time zone

      Tags:

      Feedback

          Share this page

          Got it! Feel free to add a comment
          To share your product suggestions, visit the Idea Portal.
          Please let us know how to improve this content

          Check any that apply

          To share your product suggestions, visit the Idea Portal.
          Confirm

          We were unable to find "Coaching" in Jakarta. Would you like to search instead?

          No Yes
          • Contact Us
          • Careers
          • Terms of Use
          • Privacy Statement
          • Sitemap
          • © ServiceNow. All rights reserved.

          Subscribe Subscribed Unsubscribe Last updated: Tags: January February March April May June July August September October November December No Results Found Versions Search preferences successfully updated My release version successfully updated My release version successfully deleted An error has occurred. Please try again later. You have been unsubscribed from all topics. You are now subscribed to and will receive notifications if any changes are made to this page. You have been unsubscribed from this content Thank you for your feedback. Form temporarily unavailable. Please try again or contact  docfeedback@servicenow.com  to submit your comments. The topic you requested does not exist in the release. You were redirected to a related topic instead. The available release versions for this topic are listed There is no specific version for this documentation. Explore products Click to go to the page. Release notes and upgrades Click to open the dropdown menu. Delete Remove No selected version Reset This field is required You are already subscribed to this topic Attach screenshot The file you uploaded exceeds the allowed file size of 20MB. Please try again with a smaller file. Please complete the reCAPTCHA step to attach a screenshot
          Log in to personalize your search results and subscribe to topics
          No, thanks Login