Adding attachments to Email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 08:07 AM
We want to send attachment available in sctask1 through email .The email gets trigger after closure of sctask 6. We wrote the business rule at certain condition but it is not working . can anyone please help me how to get this ?
(function executeRule(current, previous /*null when async*/ ) {
// var ins = current.instance;
var at = new GlideRecord("sc_task");
at.addQuery('short_description', 'STARTSWITH', 'Attach Signed Lease');
at.query();
while(at.next()){
var syid= at.getUniqueValue();
}
var gr = new GlideRecord("sc_task");
var ins = gr.get(current.instance);
if (ins) {
var grSysAtt = new GlideRecord('sys_attachment');
grSysAtt.addQuery("table_sys_id", syid);
grSysAtt.query();
while (grSysAtt.next()) {
var content = new GlideSysAttachment().getContentStream(ins.sys_id);
new GlideSysAttachment().writeContentStream(current, grSysAtt.getValue('file_name'), grSysAtt.getValue('content_type'), content);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 08:25 AM
HI @Adityanshu Sing Try below Code
(function executeRule(current, previous /*null when async*/) {
var task1 = new GlideRecord("sc_task");
task1.addQuery('short_description', 'STARTSWITH', 'Attach Signed Lease');
task1.query();
var task1SysId = '';
if (task1.next()) {
task1SysId = task1.getUniqueValue();
}
if (task1SysId) {
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_sys_id', task1SysId);
attachmentGR.query();
var attachments = [];
while (attachmentGR.next()) {
attachments.push(attachmentGR.sys_id.toString());
}
if (attachments.length > 0) {
var email = new GlideEmailOutbound();
email.setSubject('Attachments from sc_task');
email.setBody('Please find the attachments from sc_task.');
email.addAddress('to', 'recipient@example.com');
for (var i = 0; i < attachments.length; i++) {
email.addAttachment(attachments[i]);
}
email.send();
}
}
})(current, previous);
Regards,
Sid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 07:10 AM
Hi @The Matrix - I haven't found any official documentation or evidence that GlideEmailOutbound includes an addAttachment method. Is this code perhaps generated by a GPT model? From my understanding, there isn’t a built‑in way to attach files directly with GlideEmailOutbound. This is supported by KB0789188:
As of now there is no attachment manipulation is available in GlideEmailOutbound from scripting layer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 02:56 AM
@The Matrix , We want to include the sctask description in email body and also need to send email with assignment group in cc. can you please help me how to get this with your logic or how can we leverage the notification (created on sc_task table) in this logic ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2025 08:50 AM
Hi @Adityanshu Sing ,
In the related link of the Notification, click Advance View
Then, in 'What it will contain', click 'Include Attachments'
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.