Retrieve attachment from RITM to the import set staging table and transform records to Target table

Biso_Boby
Tera Contributor

Hi All,

 

I would like to know how i can retireve RITM attachment to the import set staging table and then transform records accordingly to target table. and finally i need to archive this loaded attachment imprt set row into archive folder.

Currently Im working on Hardware Asset Management scope.

Im using below BR script(On After insert/update) but  got to know few methods/APIs like GlideSysattachment() wont work in some scenarios.

 

(function executeRule(current, previous /*null when async*/) {


var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_sys_id', current.sys_id);
attachmentGR.addQuery('table_name', 'sc_req_item');
attachmentGR.query();

if (attachmentGR.next()) {
    var attachmentSysId = attachmentGR.sys_id;
    gs.info('Attachment Retrieved: ' + attachmentSysId);

   
   
}

 var importSetSysId = 'import_set_SYS_id';
 var attachment = new GlideSysAttachment();
var content = attachment.getContent(attachmentGR);
if (content) {
    gs.info("Attachment is there: " +  attachmentGR);
    return;
}
else {
    gs.info("Attachment is there: " +  attachmentGR);
}


var lines = content.split("\n");
if (lines.length < 2) {
 gs.addInfoMessage("CSV must have header and atleast one row");
return;
 }
var csvParser = new sn_impex.GlideCSVParser();
csvParser.parse(content);

while (csvParser.next()) {
    var row = new GlideRecord('sys_import_set_row');
    row.initialize();
    row.import_set = importSetSysId;
    row.col1 = csvParser.getValue('u_model');
    row.col2 = csvParser.getValue('u_substate');
     row.col3 = csvParser.getValue('u_serial_number');
    row.col4 = csvParser.getValue('u_model_category');
     row.col5 = csvParser.getValue('u_state');
    row.col6 = csvParser.getValue('u_stockroom');
    row.insert();


}

var transformMapSysId = 'transform_map_SYS_id';

var transformEvent = new GlideImportSetTransformer();
transformEvent.setImportSetID(importSetSysId);
transformEvent.setTransformMapID(transformMapSysId);
transformEvent.transform();

})(current, previous);

 

@Ankur Bawiskar @Sandeep Rajput 

12 REPLIES 12

yesubabu Jonnal
Tera Contributor

Use a script or query to get the attachments linked to the RITM:
use Attachment API to download and re-upload it to the staging record.
Flow Designer - We have OOTP copy attachment function Use it


Use Below API

var attachment = new GlideSysAttachment();
attachment.copy('sc_req_item', ritmId, 'your_import_set_table', importSetRecord.sys_id);

Ankur Bawiskar
Tera Patron
Tera Patron

@Biso_Boby 

what's your actual business requirement?

You want to fetch attachments from RITM and do what with them?

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

I need to bulk upload assets into hardware table, So once the catalog item is submitted with attachment, it generates an RITM. So here, I need to get that attachment from RITM, and process further to upload all the records in attachment into target table(Hardware). For that Im trying to do via import set staging table and Transform records into target table

@Biso_Boby 

1) so user submits catalog item with lets say 5 files, it created RITM and adds these 5 files to RITM

2) how is this RITM linked with hardware table?

3) are you having any variable referring to hardware table in your catalog item?

4) if yes then are you saying those 5 files you want to add to that Hardware record selected in the Reference variable?

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