Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Inbound action to import attachment

Tom Lapkowicz
Tera Expert

Hello.  I am trying to create an Inbound Action that will take the email attachment (in xlsx format) and automatically import it.  The sys_id of the table to import the records to is 679c4e6d1b9fd2105a48ca65604bcbce and the sys_id of the transform map is 79acce6d1b9fd2105a48ca65604bcb7c.  I've tried to use several different scripts that I found in the community but they all give me a message "a suitable GlideRecord not found".  Any idea what I am doing wrong?  Thank you.

3 REPLIES 3

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @Tom Lapkowicz - Please share your code.

Gangadhar Ravi
Giga Sage

@Tom Lapkowicz you can copy the attachment to data source and trigger data source from script.

 

 

GlideSysAttachment.copy('sys_email',current.sys_id,'sys_data_source','data_source_sys_id');

 

create a schedule data import keep it active false since you will be triggering it from schedule job

 

 

var schImp_GR = new GlideRecord('scheduled_import_set');
schImp_GR.addQuery('name','<NameOfDataImport>');
schImp_GR.query();
if(schImp_GR.next()){
SncTriggerSynchronizer.executeNow(schImp_GR); // this will work in global scope

//gs.executeNow(schImp_GR); // this will work in scoped app

}

 

 Please mark my answer correct and helpful if this works for you.

PritamG
Mega Guru

t

if (email.attachments.length > 0) {
    var attachment = email.attachments[0];
    
    var importAPI = new GlideImportSetAPI();
    var importSetID = importAPI.createImportSetTable('679c4e6d1b9fd2105a48ca65604bcbce'); 
    var importSetRun = importAPI.createImportSetRun(importSetID);
    
    var loader = new GlideExcelParser();
    loader.process(attachment.sys_id, importSetID, importSetRun.getSysID());
    
    var transform = new GlideImportSetTransformer();
    transform.setImportSetRun(importSetRun.getSysID());
    transform.setTransformMap('79acce6d1b9fd2105a48ca65604bcb7c');
    transform.transform();
    
    gs.log("Import successful from email attachment.");
} else {
    gs.log("No attachment found in email.");
}

 

ensure the sys_id of the target table and transform map are correct and the attachment must be processed using GlideExcelParser if it's in .xlsx format.