how to attach Catalog Item attachments to Workflow Notification activity using Email Script

KeDix
Tera Expert

how to attach Catalog Item attachments to Workflow Notification activity using Email Script.

 

The following code in the Email Script is not working. There is no attachment in the attachments tab of the email.

---------------------------------------------------------------------------------------------------------------------------------------

var attachmentVariable = 'portrait_image';//Attachment variable
 
// Get the attachment
  var attachmentGR = new GlideRecord('sys_attachment');
  //attachmentGR.addQuery('table_name', 'sc_req_item');
attachmentGR.addQuery('table_name', 'ZZ_YYsc_cart_item');
  attachmentGR.addQuery('table_sys_id', current.sys_id);
  attachmentGR.addQuery('file_name', current.variables[attachmentVariable].name);
  attachmentGR.query();
 
if (attachmentGR.next()) {
email.addAttachment(attachmentGR); // Attach the file
gs.info(attachmentGR);
  }
---------------------------------------------------------------------------------------------------------------------------------------
Thanks in Advance
3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@KeDix When a user uploads an attachment on a catalog item, initially the table name for that attachment gets recorded as 'sc_cart_item'. However, once the submit button on catalog item is pressed a request gets created and the same attachment gets transferred to the request and the table name and sys_id fields of the attachment are updated accordingly.

 

In your case, I am assuming the request has already been created, hence you should use attachmentGR.addQuery('table_name', 'sc_req_item');

 

Also, for the testing purposes, just comment the line  attachmentGR.addQuery('file_name', current.variables[attachmentVariable].name); and see if the query returns the result.

Yes. Submit button is clicked and then I am using Notification Activity in the workflow. This notification activity uses EmaiScript.

 

I used  attachmentGR.addQuery('table_name', 'sc_req_item'); but that did not work previously hence I changed the table name to 'ZZ_YYsc_cart_item' by looking at the attachment table.

 

I have now changed the table name to as you have suggested and commented code too. But I could not see the attachment after opening the email record.

@KeDix After creating the request, I suggest you to run the following script in Background Script console and check the result printed by the script.

 

 var attachmentGR = new GlideRecord('sys_attachment');
  attachmentGR.addQuery('table_name', 'sc_req_item');
  attachmentGR.addQuery('table_sys_id', current.sys_id); //replace the sys_id with the sys_id of the request
 // attachmentGR.addQuery('file_name', current.variables[attachmentVariable].name);
  attachmentGR.query();
 
if (attachmentGR.next()) {
//email.addAttachment(attachmentGR); // Attach the file
gs.info('This is sys_id of the attachment '+attachmentGR.getValue('sys_id'));
  }

In the above script, simply replace the current.sys_id with the sys_id of the request and run the script to check if the log gets printed.