Auto-import attached file from RITM Table into target table

jyotimalhot
Tera Contributor

Hello Everyone,

 

Does anyone here already done, import an attached CSV File from RITM Table in to Target table? We are creating one service request with CSV attachment from portal and from RITM number trying to import attached CSV  file into Target Table 'cmdb_ci_outage' . 

Thank you in advance.

 

Thanks

JM

2 REPLIES 2

Tai Vu
Kilo Patron
Kilo Patron

Hi @jyotimalhot 

You can think of having steps like below for your catalog item:

1. Create a data source with the File type (CSV, XLSX) data load

2. Attach (or replace) the attachment from the Requested Item.

3. Create a schedule data import, which will be executed using script.

4. Use SncTriggerSynchronizer.executeNow(current) to execute the import in your catalog item flow.

 

You can also have a look to the below article. The post shows details of steps by steps how to import from inbound email.

Ref: Loading data from an email attachment

 

Cheers,

Tai Vu

Hi Timi,

 

We are creating  service request with CSV attachment from portal and from RITM number trying to import attached CSV  file into Target Table 'cmdb_ci_outage' . Everytime, if we will create new Service Request with CSV attachment from portal then previous attachment should get delete from Data source table and new attachment should get inserted in to data source table and attachment content should get import into target table i.e. 'Cmdb_ci_outage'. 

 

I'm following below approach:

 

Created a data source with the File type CSV.

Created transform map with field maps - Source, target and Coalesce and set the Target table as well.

Created Scheduled Data import.

Created Business Rule with below script.

 

(function executeRule(current, previous /*null when async*/) {
 
current.hasAttachments();
 
var dataSourceSysId = '8bbeb3f133389250b3e0b4023d5c7b8a'; // sys_id of the data source  created 
 
var gr = new GlideRecord('sys_data_source');
gr.addQuery('sys_id',dataSourceSysId);
gr.query();
if(gr.next()){
 
//deleting existing attachment while inserting new RITM Attachment to the data sorce table
var attach = new GlideRecord("sys_attachment");
        attach.addQuery("table_name", "sys_data_source");
        attach.addQuery("table_sys_id", dataSourceSysId);
        attach.query();
        if (attach.next()) {
            attach.deleteRecord();
        }
//INSERT NEW ATTACHMENT
        GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source',
'8bbeb3f133389250b3e0b4023d5c7b8a');
 
}
 
var schImp_GR = new GlideRecord('scheduled_import_set');
 
schImp_GR.addQuery('data_source',dataSourceSysId);
 
schImp_GR.query();
 
if(schImp_GR.next()){
 
SncTriggerSynchronizer.executeNow(schImp_GR); 
 
}
 
})(current, previous);
 
 
Scheduled import executing successfully But, attached file data not getting import in Target table 'Cmdb_ci_outage'.
 
Thanks
JM