can we execute data sources(import sets) from background

Naveen Velagapu
Mega Guru

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 ?

18 REPLIES 18

excellent Michael, thanks for that link.  One question...does that script account for repeat data?  In other words, preventing duplicate records from being created?

 

That solution doesn't but the script could certainly scan the import set rows looking for duplicates based on some criteria before they are imported.

If the concern is duplicate CI's say based on serial number it is best to put a solution at the business rule level preventing insert.  This way it is centrally managed.

Excellent Michael, thanks!

Hi Michael,

I'm running into trouble with my script...it was working fine in my personal instance creating [cmdb_ci] records.

In my company's instance I'm trying to use the same process and logic to populate [cmdb_ci_server] records from a spreadsheet attached to catalog item.  I created the import set table and transform maps the same way I did in my sandbox and did a test load manually and it worked.

See anything that might be wrong with my script?  This is a Run Script in my workflow.

 

 

var sysID = current.sys_id;

//create new record on 'sys_data_source' table
var impRec = new GlideRecord('sys_data_source');
impRec.initialize();
impRec.name = 'Testing adding and transforming Xcel';
impRec.import_set_table_name = 'u_cmdb_ci_server';
impRec.format = 'Excel';
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, '6af70349dbe548501863f3551d96192e');//transform map sys_id
transformWorker.setBackground(true);
transformWorker.start();

 

and this is the error I'm getting in the activity when I submit the catalog item with the spreadsheet.

 

find_real_file.png

Patrick, line 17 the following?

var ranload = loader.loadImportSetTable(importSetRec, impRec);

If so its likely complaining about 'impRec' being NULL.  This is because you inserted it a few lines above and may need to add the following to re-establish that variable:

impRec.initialize();
impRec.get(targetSysID);

Insert it between these lines:

GlideSysAttachment.copy('sc_req_item', sysID,'sys_data_source',targetSysID);

// Re-establish impRec variable
impRec.initialize();
impRec.get(targetSysID);

// Process data source file