added an action to import a CSV file into the database, but only file was updated in the DataSourc

艶博李
Giga Contributor

 

I added an action to register the CSV file into the database after attaching it, and although the file in the Data Source was updated, the contents of the CSV were not reflected as data in the database.

In the flow, I set att_sys_id (the sys_id of the attached file) as an input.

 

javascript

(function execute(inputs, outputs) {

// Data Source sys_id
var grDataSource = new GlideRecord("sys_data_source");
// DATA SOURCE SYS ID
if (!grDataSource.get('175768c183eb6290d751a270ceaad389')) {
gs.error("no data source");
return;
}
gs.info("test1111111111");

// Import Set
var loader = new GlideImportSetLoader();
var importSetGr = loader.getImportSetGr(grDataSource);
gs.info("test222222222");


loader.setAttachmentId(inputs.att_sys_id); /
loader.loadImportSetTable(importSetGr, grDataSource);
gs.info("test3333333333");

var importSetRun = new GlideImportSetRun(importSetGr.sys_id);
var importLog = new GlideImportLog(importSetRun);
var importTransformer = new GlideImportSetTransformer();

importTransformer.setLogger(importLog);
importTransformer.setImportSetRun(importSetRun);
//importTransformer.setImportSetID(importSetGr.sys_id);
importTransformer.setSyncImport(true); // If true, script will wait for transform to finish
importTransformer.transformAllMaps(importSetGr);
gs.info("test44444444444");

})(inputs, outputs);

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@艶博李 

Did the data get loaded in staging table?

is that data source having a transform map associated with it for your target table?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

Thank you for your response. The issue has been resolved.
Added processing to set the attachment file to the data source.


// source
var gsa = new GlideSysAttachment();
gsa.deleteAll(ds);

gsa.copy('sc_req_item', reqitemSysId, 'sys_data_source', dataSourceSysId);
fixAttachmentTableName(dataSourceSysId);

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@艶博李 

Did the data get loaded in staging table?

is that data source having a transform map associated with it for your target table?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you for your response. The issue has been resolved.
Added processing to set the attachment file to the data source.


// source
var gsa = new GlideSysAttachment();
gsa.deleteAll(ds);

gsa.copy('sc_req_item', reqitemSysId, 'sys_data_source', dataSourceSysId);
fixAttachmentTableName(dataSourceSysId);