Inbound action to import attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 11:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 01:57 PM
Hi @Tom Lapkowicz - Please share your code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 05:46 PM - edited 01-24-2025 05:47 PM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2025 09:21 PM
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.