Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Automate System Import with script

julia65
Tera Contributor

Hi! I am trying to automate the system import process. Essentially, from the servicenow catalog I want the user to be able to attach an excel spreadsheet, have it loaded into a data source, then a staging table, then transform it to a maintenance table... but ultimately I just want each row in the excel spreadsheet to be a new record created in the maintenance table. 

 

The script I have successfully creates a data source for the spreadsheet but doesn't import the data into the staging table or the maintenance table. I was wondering if anyone else stumbled across this issue? Below is what I have and I'm doing this through Record Producer.

 

Additionally, for every attachment I get

 

var transformMapSysIDs = 'ca72a6091b5b25187a74ca262a4bcba3';
//loads excel into datasource
current.name = gs.getUserName() + " Import at: " + new GlideDateTime();
current.import_set_table_name = 'x_inprf_contract_0_staging_table';
current.file_retrieval_method = "Attachment";
current.type = "File";
current.format = "Excel";
current.header_row = 1;
current.sheet_number = 1;
dsr = current.insert();
gs.info('Data Source' + dsr);

GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', dsr);
//imports data into staging table
var ds_sys_id = dsr;
var dataSource = new GlideRecord('sys_data_source');
dataSource.get(ds_sys_id);
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(dataSource);
var ranload = loader.loadImportSetTable(importSetRec, dataSource);
importSetRec.state = "loaded";
importSetRec.update();

var transformWorker = new GlideImportSetTransformerWorker(importSetRec.sys_id, transformMapIDs);
transformWorker.setBackground(true);
transformWorker.start();
0 REPLIES 0