Can I run scheduled jobs from postman or curl comm... - ServiceNow Community

Can I run scheduled jobs from postman or curl command ?

Aman11
Giga Contributor

Hi Team,

I have written a scheduled script in global application. I want it to execute from external environment like postman or curl commands. Is it possible ? If yes please tell me step how to achieve it ?

 

Thanks in advance !!!

Aman

4 REPLIES 4

Chuck Tomasi
Tera Patron

Scheduled jobs are done on a schedule - hence the name. 🙂 They should not be triggered by an external trigger.

If your aim is to run a script on demand based on an external trigger, I recommend looking at Flow Designer, or a business rule (if you have to run script). You can create a very simple table that creates records and then BR or Flow reacts to that. So you get a log entry that validates your API is working (e.g. table REST API that creates records) and that triggers the functionality you have in your current scheduled job.

HugoFirst
Kilo Sage

Chuck's excellent answer is right on, as usual!  There is another option that you could consider, the Scripted REST API.  In this option you can write the script and assign it to a URL.  By calling the URL with CURL, you will invoke the script.  Does this meet with your intention?

 Here are some links to helpful docs for this:

Scripted REST APIs:
https://docs.servicenow.com/bundle/newyork-application-development/page/integrate/custom-web-service...

Examples:
https://docs.servicenow.com/bundle/newyork-application-development/page/integrate/custom-web-service...

 

DrewW
Mega Sage
Mega Sage

You can create a Scripted REST API to tell the system what job to run but simply passing the needed information about the job (sys_id or name) to kick off then do

SncTriggerSynchronizer.executeNow(current);

where current is a GlideRecord that is the scheduled job you would like to run.

the reason I did this is because we had a scheduled import that would run once a week and now and then the people in control of the data would need to push changes right now, so we did this so they could remotly tell the import to run.  There are also several other reasons it can be usful to do it and it allows a simple solution that does not have a bunch of moving parts.

 

Chuck Tomasi
Tera Patron

By the way, I covered your question, answer, and some additional thoughts on the NOWCommunity Live Stream on 2019-12-09.

Video: Community Live Stream - 2019-12-09 - Developer Community - ServiceNow Community