Bulk Upload of records using Inbound Action

Manaswini
Tera Contributor

I have created an Inbound email action where Data source is the target table. In this case, I am checking the body of the email as first step. If body of the email i.e., vendor (in script) exits on control table then the attachment attached in the email should work on the data source table mentioned in the script.
But somehow my script is not working on data source table (the attachment is not getting updated). Can anyone help me.

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Check if the body of the email exists in the profile field of the control table
var vendor = email.body.vendor_organization_name;
var controlTable = new GlideRecord('sn_compliance_control'); // Replace with the actual table name
controlTable.addQuery("profile", vendor);
controlTable.query();
if (controlTable.next()) {
// The email body exists in the control table, execute the code below
// Set the Data Source to be used
var dataSourceID = "d767ff601bbd71104444415de54bcbdc";
// Query the attachments for this data source and delete them
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'sys_data_source');
gr.addQuery('table_sys_id', dataSourceID);
gr.query();
while (gr.next()) {
gs.info("success in running 16th line of code");
gr.deleteRecord();
}
//Copy attachment from the Email to the Data Source
GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'sys_data_source', dataSourceID);
gs.info(" success in running 22nd line of code");
var gr1 = new GlideRecord('sys_data_source');
gr1.addEncodedQuery("name=VSC Checklist");
gr1.query();
while (gr1.next()) {
gr1.update();
}
gs.info(" success in running 28th line of code");
}
})(current, event, email, logger, classifier);
6 REPLIES 6

Copy of attachments take place on sys_attachment table, hence no updates will take place on sys_data_source table. However, the attachments will show up sys_data_source table once the GlideSysAttachment.copy method is called.

 

Please open the record having sys_id d767ff601bbd71104444415de54bcbdc on sys_data_source table and check if it shows the attachments there? Ideally the attachment should have been copied via the script shared above. 

Yes, that was the issue, the attachment is not updating on the data source.