is it possible to call a processor from a background script

Ravish Rawat
ServiceNow Employee
ServiceNow Employee

is it possible to call a processor from a background script

7 REPLIES 7

Jon Barnes
Kilo Sage
Are you wanting to test your processor? I doubt you would be able to call it from a background script but you could potentially try with using a rest message to hit it. Otherwise you could go to the processor url in your browser and test that way or do a post to it depending on the type of interaction it expects

Hi @Jon, thank you for your reply.  I upvoted this question yesterday as I am also interested in this question.

 

In my case, I want to programatically call the URL to the processor, within a loop where I fill in sysparm variables programmatically.

 

I have implemented the SNGuru solution to capturing all attachments on a task as a ZIP file which introduces a processor called "exportAttachmentsToZip".  It is designed to be called via a UI Action which does an action.setRedirectURL() call with sysparms in the URL.


I would like to programmatically call this functionality by generating my own URLs, in something like the following (in a background script or a scheduled job script):

var gr = new GlideRecord('incident');
gr.addEncodedQuery('sys_created_on>=' + gs.beginningOfThisYear());
gr.query();
while (gr.next()) {
   var URL = 'exportAttachmentsToZip.do?sysparm_sys_id=' + gr.sys_id + '&sysparm_table=incident';
   gs.print('URL = ' + URL);
   // call exportAttachmentsToZip.do processor with URL variable from above, here
}

I don't think it is possible to do within a script, but wanted to confirm.

 

Thanks for any thoughts you can provide!

Julie

The only thing I think might be possible is using rest to call the processor. Do you need your script to do something with the output of the processor or just interested in triggering the processor functionality and don’t care about what it returns?

Thanks for your reply, Jon.  In answer to your question, don't care about what the call returns.  I had a quick look and I figure this would be a Scripted REST API if it was possible at all, plus I'd have to translate my output (which should be a .zip file) from the encoded format back to .zip.  Complicated.

In the end I decided to use "Macro Express" (a cool little piece of software!) to automate the copy & paste of the URL generated from my script, from notepad, to a browser window.  Works like a charm!

Thanks for your replies and attempts to help!