can we execute data sources(import sets) from background

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2016 04:33 AM
can we execute data sources(import sets) from background ? i.e. instead creating a scheduled import and execute it from background is there any package or util which will execute data source and transform map manually?
or else does
SncTriggerSynchronizer.executeNow('scheduled import sys_id'); has capability to execute the data source without creating scheduled import ?
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2016 05:30 PM
I have automated excel imports via attachment on a record producer. The same logic should apply so thought I would share.
You can process a data source by the following script:
// Process excel file
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(DATA-SOURCE-GLIDERECORD);
var ranload = loader.loadImportSetTable(importSetRec, DATA-SOURCE-GLIDERECORD);
importSetRec.state = "loaded";
importSetRec.update();
Then you can transform the data from that data source specifying the SysID of the transform map to utilize:
// Transform import set
var transformWorker = new GlideImportSetTransformerWorker(importSetRec.sys_id, TRANSFORM-MAP-SYSID);
transformWorker.setBackground(true);
transformWorker.start();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2016 02:44 AM
thanks Michael Ritchie , ill try out the mentioned

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2016 09:29 AM
Hi,
I have tried above code but still data source is not able to execute and no records inserted in import set table.I am getting XML file from SOAP webservices. and attached to Data Source now I want to execute the data source and transform map.
Can you please guide me ?
var createNewAttach1 = new GlideRecord('ecc_queue');
createNewAttach1.initialize();
createNewAttach1.agent='AttachmentCreator';
createNewAttach1.topic='AttachmentCreator';
createNewAttach1.name='uCMDB-Application-Server-Inbound-File.xml:application/xml';
createNewAttach1.source='sys_data_source:'+gs.getProperty('application.server.data.source.sysid');
createNewAttach1.payload=request.basefilestream;
createNewAttach1.insert();
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(gs.getProperty('application.server.data.source.sysid'));
var ranload = loader.loadImportSetTable(importSetRec, gs.getProperty('application.server.data.source.sysid'));
importSetRec.state = "loaded";
importSetRec.update();
var transformWorker = new GlideImportSetTransformerWorker(importSetRec.sys_id, 'transform_map_sys_id1');
transformWorker.setBackground(true);
transformWorker.start();
gs.sleep(60000);
var transformWorker2 = new GlideImportSetTransformerWorker(importSetRec.sys_id, 'transform_map_sys_id2');
transformWorker2.setBackground(true);
transformWorker2.start();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 04:47 PM
Thanks Michael for the great script!...I added some elements to form a single Run Script activity in a workflow running on the specific catalog item that automatically populates records to the [cmdb_ci] table from a spreadsheet attached to a catalog item in the Service Portal.
This script handles all the logic to load the data, transform it and populate records to the [cmdb_ci] table. Need to also credit Aman Reddy Gurram's post on https://community.servicenow.com/community?id=community_question&sys_id=da073cb5dbec6f8ca39a0b55ca96...
Here's my Run Script activity:
var sysID = current.sys_id;
//create new record on 'sys_data_source' table
var impRec = new GlideRecord('sys_data_source');
impRec.initialize();
impRec.name = 'this can be whatever name you want';
impRec.import_set_table_name = 'this is the name of the import set table you'll use';
impRec.format = 'Excel';//whatever format your catalog item is accepting
var targetSysID = impRec.insert();
//copy attachment to the [sys_data_source] record
GlideSysAttachment.copy('sc_req_item', sysID,'sys_data_source',targetSysID);
// Process data source file
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(impRec);
var ranload = loader.loadImportSetTable(importSetRec, impRec);
importSetRec.state = "loaded";
importSetRec.update();
//Transform import set
var transformWorker = new GlideImportSetTransformerWorker(importSetRec.sys_id, '6bcff3cadb8100100ed48e4748961974');//transform map sys_id
transformWorker.setBackground(true);
transformWorker.start();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2019 06:15 PM
Patrick, thank you for sharing. I actually documented that use case here using a single record producer 😁:https://community.servicenow.com/community?id=community_blog&sys_id=341eae2ddbd0dbc01dcaf3231f961994