Inbound Email Action Not Triggered and not Copying sys_email Attachments into Import Set – Need Help

neehas
Tera Expert

Hi Everyone,

I’m working on an inbound email action to automate CyberArk datatable updates.
The process is:

  1. User sends an email with an Excel template

  2. My inbound email script creates an import set

  3. Attachments from sys_email should be copied into the import set

  4. A transform map processes the data

 Inbound Email Action is NOT triggering

Even when sending an email with the correct subject, the inbound action is not firing.

I have already checked:

  • Action is Active

  • Condition uses the correct Subject Contains value

  • User sending the email exists in the system

  • Instance can receive emails (inbound working)

But the script is not running at all (no logs in system log).

However, the attachments are not getting copied.
I suspect the issue is related to how the script fetches attachments using table_sys_id of the email record (sys_id vs uid).

Here is the script I am currently using:

(function runAction(current, event, email, logger, classifier) {

// Create import set
var imp = new GlideRecord('sys_import_set');
imp.initialize();
imp.data_source = '407fdb7987f0d210654653973cbb359c';
imp.table_name = 'u_cyberark_data';
var impSysID = imp.insert();
gs.info("Import Set: " + impSysID);

// Copy email attachments into import set
var sa = new GlideSysAttachment();
var att = new GlideRecord('sys_attachment');
att.addQuery('table_name', 'sys_email');

// Using sys_id + uid of the email
var qc = att.addQuery('table_sys_id', email.getRecord().getValue('sys_id'));
qc.addOrCondition('table_sys_id', email.getRecord().getValue('uid'));

att.query();
gs.info("Email sys_id: " + email.getRecord().sys_id);

while (att.next()) {
sa.copy(att.table_name, att.sys_id, 'sys_import_set', impSysID);
gs.info("Copied attachment: " + att.sys_id);
}

// Trigger transform
var tm = new GlideRecord("sys_transform_map");
tm.addQuery("name", "Cyberark Data Table Map");
tm.query();

if (tm.next()) {
var transformer = new GlideImportSetTransformer();
transformer.transformAllMaps(impSysID, tm.sys_id);
}
})(current, event, email, logger, classifier);





2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@neehas 

check these links and enhance your code

Auto load Excel spreadsheet using Email Inbound Action 

Loading data from an email attachment 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@neehas 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader