Run Scheduled Import via API call

bigbacon
Giga Guru

Is this possible to do? We have a lot of data movement and automated processes that run local on a server to do various things outside of ServiceNow. One of the things I'd like to add to this is the ability to run a scheduled job via the ServiceNow Rest API. 

 

Is that possible to do?

5 REPLIES 5

Bhuvan
Tera Sage

@bigbacon 

 

Check if you have the ability to invoke scheduled jobs via API. For example, refer below article

 

https://learn.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page

 

If answer is yes, you can use ServiceNow REST API to invoke the task scheduler API to trigger the scheduled jobs.

 

Thanks,

Bhuvan

Bhimashankar H
Mega Sage

Hey @bigbacon ,

 

Absolutely, this can be done using flow designer, easy to understand, clean and maintainable. 

 

Steps to achieve this:

  1. First create REST message with GET HTTP method to call the rest API, meaning get the endpoint from where you want to get the data.
  2.  Test if getting the data
  3. Copy the code from 'preview script usable' button shown on GET method screen.
  4.  Ensure you have the integration hub installed. Create a custom action, if you want to have any parameter/input, add the script step in action. (You may create the data stream to handle the data iteration)
  5.  In script step paste the copied script usage and iterate over the data.
  6.  Create one staging table extending the 'sys_import' table and specify the target table as well.
  7. Create the right transform map.
  8. Now in script step iterate over the data and insert that data with all required field in staging table.
  9. Once it is inserted in staging table, as it is extended from 'sys_import' it will automatically run the transform map. No need to run explicitly.
  10. Now create a one new flow designer with appropriate trigger condition and add the created custom action in action.
  11. Once it is created successfully, test and activate the flow designer.

 

This way you can schedule the data import using REST API.

 

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

bigbacon
Giga Guru

The question is it possible to make a call to the SN API to say "Hey, run this scheduled import." 


Hi @bigbacon ,

 

Yes, by using the flow designer's trigger condition. So every flow designer has trigger condition, so that you can schedule to run at specified time like every day at 9 AM, when record is inserted in particular table or a field is update or application scope.

 

Then in action, you will have to create a custom action with the help of integration hub, as you are going call the REST API.

 

See the attached screenshot.

 

BhimashankarH_1-1754057166370.png

 

 

 

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!