The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Allow user to run scheduled import on demand

bradleyperkins
Giga Contributor

We run a number of scheduled imports during off hours that bring in data for custom application. These imports use a mid server and JDBC to connect to our databases. The queries are designed to return only updated or new rows and the imports run quickly.

We have a need to allow a few non-admin users that manage the process the custom application supports to run those imports on demand during the day. I'd like to provide them with the capability to run an import at any time without giving them direct access to the Scheduled imports table.

This would be accomplished via a button that would appear on a table list or a navigator menu item. This would effectively perform the same action that the Schedule Import form "Execute Now" button does.

Can anyone suggest how we might provide this feature?

9 REPLIES 9

sachin_namjoshi
Kilo Patron
Kilo Patron

You can configure UI action on your table list and use below code to run your scheduled job.



var rec = new GlideRecord('sysauto_script');


rec.get('name', 'YOUR_JOB_NAME_HERE');


if (typeof SncTriggerSynchronizer != 'undefined')


    SncTriggerSynchronizer.executeNow(rec);


else


    Packages.com.snc.automation.TriggerSynchronizer.executeNow(rec);



Regards,


sachin


Sachin,



The import isn't a Scheduled script. Its table would be 'scheduled_import_set'. Can similar logic be applied to that table?



Edit: It probably can. The Script for the Schedule Import Form's "Execute Now" button UI Action looks like:



current.update();


SncTriggerSynchronizer.executeNow(current);



Thanks,



Brad


You can process a data source by the following script:




  1. // Process excel file  
  2. var loader = new GlideImportSetLoader();  
  3. var importSetRec = loader.getImportSetGr(DATA-SOURCE-GLIDERECORD);  
  4. var ranload = loader.loadImportSetTable(importSetRec, DATA-SOURCE-GLIDERECORD);  
  5. importSetRec.state = "loaded";  
  6. importSetRec.update();  

Then you can transform the data from that data source specifying the SysID of the transform map to utilize:




  1. // Transform import set  
  2. var transformWorker = new GlideImportSetTransformerWorker(importSetRec.sys_id, TRANSFORM-MAP-SYSID);  
  3. transformWorker.setBackground(true);  
  4. transformWorker.start();  


Regards,


Sachin


Sachin,



GlideImportSetLoader is not allowed in scoped applications either. I should have mentioned that to begin with.


I tried to prefix it with global.GlideImportSetLoader, but no luck.



Where are GlideImportSetLoader and GlideImportSetTransformerWorker documented?


I've checked docs.servicenow.com, googled, etc. I can find examples of usage, but no details.