Execute Scheduled Jobs From Script

Scheduled jobs are an extremely useful way to automate processes in Service-now.com and lift some of the administrative burden of the tool off of the shoulders of your Service-now administrators. It’s very easy to create a scheduled job or a scheduled import. Typically there’s no scripting or advanced configuration involved at all. Just set it up with a schedule and let it run! There are some situations where you might need to execute a scheduled job outside of its normal schedule. You can always open up the scheduled job entry and click the ‘Execute Now’ button, but there are also probably times where you’d really like to automate the process based on some trigger in a workflow or state change in some ticket or CI.

This article shows you how you can use script to execute an already-scheduled job on-demand. To do this, you simply mimic the behavior of the ‘Execute Now’ button by querying for the scheduled job you want to execute and firing off the job. Here’s the script…

You can modify the script below by adding your scheduled job name and querying the appropriate table for your scheduled job as shown here. This will not work if you simply query the ‘sysauto’ table. You must query one of the extensions below directly.

  • ‘scheduled_import_set’ (Scheduled Import Sets)
  • ‘sysauto_script’ (Scheduled Script Execution)
  • ‘sysauto_template’ (Scheduled Template Generation)
  • ‘sysauto_report’ (Scheduled Report)
//Execute a scheduled script job
var rec = new GlideRecord('sysauto_script');
rec.get('name', 'YOUR_JOB_NAME_HERE');
if (typeof SncTriggerSynchronizer != 'undefined')

Date Posted:

November 29, 2010

Share This:


  1. Dave Richter December 9, 2010 at 3:15 am

    I have over 20 scheduled data imports, each one associated with an LDAP ou definition, each pair named the same.

    I have a post-import script in one of the 20+ that updates the date in the LDAP filter successfully, but the LDAP ou definition name is hard-coded. I want to use a script that reads the current scheduled_data_import name instead of hard-coding that name, then copy that in all 20+. However when I use “current.variable” it keeps failing because its null. There must be a universal way to pull the “current” record. (current at the time I execute the script. Thank you.

    • Mark Stanger December 9, 2010 at 5:24 am

      I don’t think you can get around hard-coding in that script field. There is a way you can cheat though so that you can dynamically pull values from the ‘current’ record for your script…and only need one script to do it all.

      You can create a ‘before’ business rule on the ‘Scheduled Data Import’ table that will check to see if the scheduled import job meets the correct criteria (LDAP source, Execute post script checked, etc.). The business rule would run before updates to the scheduled import record and populate the ‘Post Script’ field for you based on the ‘current’ scheduled import set record. This way, the ‘Post Script’ field can be hard coded as it needs to be, but it won’t truly be hard-coded because your business rule will pull the dynamic values and populate them for you. Here’s a sample script that should get you started on your business rule if you want to give this a shot.

      //If we're working with an LDAP data source and Executing a post-import script 
      if(current.data_source.type == 'LDAP' && current.post_script_bool == true){ 
         //Generate a script string to be populated in the 'Post script' field 
         var s = ''; 
         s += "//Do something here..." 
         s += "var rec = new GlideRecord('ldap_ou_config');" 
         s += "rec.addQuery(field, value);" 
         s += "rec.addQuery('field2', '" + current.name + "');"; 
         s += "rec.query();" 
         s += //Continue here...
         //Set the 'Post script' field with the script string 
         current.post_script = s; 
  2. Brian Broadhurst January 5, 2011 at 7:05 am

    The ability to trigger scheduled jobs from scripts is really useful – one of the most useful applications I have found is being able to email a spreadsheet into the system, then trigger a scheduled import job from an email inbound action to import the spreadsheet (see forum topic http://community.service-now.com/forum/2440).

    I’ve also had a requirement recently that I’ve been experimenting with “daisy-chaining” these triggers – a customer has a complex report that uses data from a number of tables – one approach we are looking at is to create a custom table and a scheduled script that reads the relevant tables and populates this table with the data required in the report. The idea is that a UI Action will trigger the scheduled script which populates the custom table then triggers a scheduled report which generates a report from the custom table and emails it to the user. Still in the early stages of experimentation.

    BTW I believe you can also trigger a scheduled Custom Chart using the sysauto_custom_chart table – I’ve never tried this (never got to grips with custom charts I’m afraid).

  3. Ajay February 4, 2011 at 10:28 am


    I am looking for a feature like we have some security, IT and some other DB groups where they have to do some task every month or for 45days or some specific days, is there a way where we can do something like schedule the job and give the time to run for every 30 or 45 days, the system should be able to run that on the mentioned date and create a Incident and assign it to the specific group????

    how to do that could you please help me..



  4. Wes Van Sickle February 7, 2011 at 7:30 am

    We have a need for a Scheduled Job that will create a Facilities Request every 180 days for a Preventive Maintenance task. I know how to create the scheduled job that will initiate this request every 180 days, but I was wondering if Service Now had the capability to begin the 180 day countdown ONLY after the last auto generated ticket was closed ?

    Any assistance would be greatly appreciated.



    • Mark Stanger February 7, 2011 at 8:04 am

      Hey Wes,

      This is possible and would probably be best accomplished by setting up some sort of business rule trigger that would actually create a scheduled job record to run once – 180 days in the future. I don’t have a pre-built script for that, but it should just be a GlideRecord insert into the scheduled job table.


  5. Abhiram Bharadwaj Diddigi October 3, 2011 at 12:29 am

    Hey Mark,
    Just curious , Where do you have all the available packages and their methods ? I always come across some handy methods which use ‘packages.’ , Wanted to know if you have them documented :)


    • Mark Stanger October 3, 2011 at 7:56 am

      I don’t have them documented, and actually their use is discouraged by ServiceNow development so you should avoid them whenever possible. In this case, there’s no other way to do it so I used the packages call.

  6. Dennis Smith December 20, 2011 at 7:13 am

    I wanted to see if there is a good client side script that I can use for scheduled reports. I would like to have a script that will check and see if the report contains any data, and if it does, then send as scheduled. If it does not contain any data I would like to have the script stop the scheduled send of that report until the next scheduled time and then to follow the logic again.

    For instance a report scheduled to run tomorrow automatically and yet there are no overdue incidents in the report for this scheduled job, the script should say that since there are no overdue incidents this week, the report does not run

    • Mark Stanger December 20, 2011 at 7:38 am

      @Dennis, I don’t have any script that would do this, but what you are asking for is possible just by checking the ‘Omit if no records:’ field on the scheduled report form.

      • Dennis December 20, 2011 at 8:14 am

        Thanks Mark, it is funny as you wrote this, I also received another reply from the SN forum for the same thing. Not sure why I did not check the form first. Will start to make this a habit before asking questions. Thanks again Mark and have a great day!!!

  7. Bryan January 3, 2012 at 11:54 am

    Thanks for the info, I’ve been looking for this syntax on the SN wiki without any luck.

    • Mark Stanger January 3, 2012 at 3:15 pm

      No problem. I’m glad it helped!

  8. MaC November 30, 2015 at 8:28 pm

    Awesome mate

  9. Travis October 26, 2016 at 7:52 am

    Just to add to this. If you are wanting to do this from a Scoped App. The line:


    needs to be changed to:


    • Mark Stanger October 26, 2016 at 7:53 am

      Thanks Travis! Great tip!

    • Ishan June 5, 2017 at 1:39 pm

      That tip ! Works like a charm !

Comments are closed.




Fresh Content
Direct to Your Inbox

Just add your email and hit subscribe to stay informed.