Scheduled Import Not working when triggering from BR

shrikant Kahar1
Tera Contributor

Hello Team,

 

I'm facing issue while scheduled import triggering from BR in Global Application.

BR Table : sc_req_item

BR Condition: After Insert

Please find the Business Rule Script Below

 

(function executeRule(current, previous /*null when async*/ ) {
    var attachment = new GlideSysAttachment();
    var attached = attachment.copy('sc_req_item', current.sys_id, 'sys_data_source', '430167151bbca61064e5ed73b24bcb27'); //datasource sysid
    if (attached) {
        gs.info('Attachment copied from: ' + current.number);
        var grImp = new GlideRecord("scheduled_import_set");
        if (grImp.get('f12f0225c3f86a1016f64bcd2b013174')) {
            gs.info('import loaded');
            //schedule data import sysid
            gs.executeNow(grImp);
        }
    }
})(current, previous);
 
Thanks in advanced
Shrikant
11 REPLIES 11

Hello @Robert H ,

I tried this as well but its not working.

shrikantKahar1_0-1745567018865.png

As import set state is in Loading only.

 

Thanks

Shrikant

Hello @shrikant Kahar1 ,

 

The "Loading" state means the system is still processing the file. Depending on the amount of data in the file it can take some time until it's done and changes to "Loaded". Have you opened the Import Set and checked if there any entries in the "Import Set Rows"?

 

Another approach would be: instead of copying the attachment to the Data Source, you can simply tell the Data Source to load the file from the original record, like this:

 

var sourceTable = 'sc_req_item';
var sourceId = current.sys_id;

var dataSourceId = '430167151bbca61064e5ed73b24bcb27';
var scheduledJobId = 'f12f0225c3f86a1016f64bcd2b013174';

var grDataSource = new GlideRecord('sys_data_source');
if (!grDataSource.get(dataSourceId)) return;
var grScheduledJob = new GlideRecord('scheduled_import_set');
if (!grScheduledJob.get(scheduledJobId)) return;

grDataSource.setValue('connection_url', 'attachment://' + sourceTable + ':' + sourceId + '/');
grDataSource.update();
SncTriggerSynchronizer.executeNow(grScheduledJob);

 

Regards,

Robert