Email Attachment when attachment is attached to the record in ServiceNow

Gowtham29
Tera Expert

Hi, I have custom table. When ever attachment is attached to any record in that custom table, I need to send a email to the caller saying that attachment is attached and have to send attachment to caller in that email. Please help me to do this ASAP. Thank you in advance

3 REPLIES 3

Weird
Mega Sage

1. Create a on insert BR which is triggered when an attachment is inserted on the Attachment table and the source table is your custom table.

2. Create a notification which is triggered by this event. Make sure the subject is unique.

3. Create an on insert BR on sys_email table which will be triggered based on a condition like

"Subject contains attachment added" and target_table=<your_table>

Then in the BR you can just add a script:

var att = new GlideRecord('sys_attachment');
att.addQuery('table_name', current.target_table);
att.addQuery('table_sys_id', current.instance);
att.orderByDesc('sys_created_on');
att.query();

if(att.next())
{
	
}

Now inside the if we still need to add logic on how to copy the attachment and this doesn't really have any good way on how to do it.

I'd recommend looking through here since snprotips has done a perfect script for it. In the section "Copying/Moving an Attachment" which will give further info on how to copy 1 attachment only.

Abhijit4
Mega Sage

Hi,

- Create on Insert BR on attachment(sys_attachment) table with Condition "table_name=your custom table name", write a script to trigger notification through gs.eventqueue() method. You would need to get caller here with script and pass parameter in eventqueue method.

- Configure notification and mark checkbox "include attachment" which will automatically copies attachment from your attachment record to notification and click checkbox "Event param1 contains recipient".

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hi,

If your issue is resolved then please mark appropriate answer as correct or helpful so that others can get benefits from it.

Thanks and Regards

Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP