Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Copying Attachment from Scheduled E-mail of report to a newly created record in another table.

SunnyDi
Tera Contributor

Hello good People,

I have requirement which I will explain briefly.

Requirement:

  1. In our instance we have a scheduled email of report, that is attaching one report to the email.
  2. The requirement is to create a ticket on sc_task table with the same attachment.

The obvious plain solution is to write a business rule on the email logs table to create a record and copy the attachment[ which is not preferrable to do]

Create an inbound action which will add the attachment to the record.

 

Are there any other good possible ways to meet this requirement.

 

Please comment your ideas, I really appreciate them.\

 

thank you.

2 REPLIES 2

Rafael Batistot
Kilo Patron

Hi @SunnyDi 

 

Try Scheduled Script 

 

Instead of relying on email logs or inbound actions, you can write a Scheduled Script Execution (Scheduled Job) that:

 

  • Queries the scheduled report execution logs (or sys_email if needed)
  • Locates the generated report attachment (sys_attachment)
  • Creates the sc_task record
  • Copies the attachment to the task (you can use GlideSysAttachment.copy())

 

var reportGr = new GlideRecord('sys_report');
if (reportGr.get('<REPORT_SYS_ID>')) {
// Create a new SC Task
var task = new GlideRecord('sc_task');
task.initialize();
task.short_description = 'Report attached: ' + reportGr.name;
task.insert();

// Copy attachments
var attachment = new GlideSysAttachment();
attachment.copy('sys_report', reportGr.sys_id, 'sc_task', task.sys_id);
}

 

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

Ankur Bawiskar
Tera Patron
Tera Patron

@SunnyDi 

you can create after insert business rule on sys_attachment table and determine the table and the table_sys_id of that of scheduled report, from there you can create sc_task and copy attachment.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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