Compose email should attach the attachments of the corresponding record automatically.

Ramkumar Thanga
Mega Sage

Hi Everyone,

 

I am trying with a requirement to add all the corresponding attachments of the record to the email draft while composing an email from Work space.

 

The following business rule script which runs with the following condition works in native UI but not in workspace.

Any idea to make this workable in workspace.

 

Table: sys_email 

>> Conditions:

Before 

Insert 

Filter condition:

Target table | is | sc_task 

Script :

 

 

 

var gr = new GlideRecord('sys_attachment');
   gr.addQuery('table_sys_id', current.target_record);
   gr.query();
    if (gr.next()) {
        
        GlideSysAttachment.copy('sc_task', gr.table_sys_id, 'sys_email', current.sys_id);
       

    }

 

 

 

Thanks !
Ramkumar

 

5 REPLIES 5

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Ramkumar Thanga 

The sys_email table behaves differently in Workspace compared to the native UI.

Try the below Script :-
var taskGr = new GlideRecord('sc_task');
if (taskGr.get(current.target_record)) {
var attachmentGr = new GlideRecord('sys_attachment');
attachmentGr.addQuery('table_sys_id', taskGr.sys_id);
attachmentGr.query();
while (attachmentGr.next()) {
GlideSysAttachment.copy('sc_task', taskGr.sys_id, 'sys_email', current.sys_id);
}
}

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


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

 
Thanks for the response..
 

Do I need to change the table where the business rule runs ? What should be the table ?

What should be the condition then.

 

Regards,

Ramkumar

use the same condition as you have given earlier

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


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

@Ravi Gaurav 

 

It doesn't works for me Ravi.

 

In workspace whenever I try to compose the email, it opens a record in this sys_email_draft table. So do I need to try with this sys_email_draft table.

 

Thanks

Ramkumar