We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

trigger email notification when an attachment is added to an incident

purushothamN599
Tera Contributor

Hi ,

 

 

Trigger email notification when an attachment is added to an incident working fine but unable send with this body

 

 

1. Attachment by: Person that attached.

2. Attachment Date: [Date/Time]

3. You can view the attachment by clicking the link below.

 

 

4. *[link should take them to the incident.]

 

Purushotham1992_0-1707105047729.png

 

 

 

Event and email Notification created on incident table 

Business rule created on Attachment table 

 

 

Thanks in advance 

1 ACCEPTED SOLUTION

Hello @purushothamN599 ,

 

Use var t = event.parm2 instead of var t=${event.parm2}

View solution in original post

18 REPLIES 18

Hello @purushothamN599 ,

 

Please update your business rule and mail scripts as below

 

Business rule:

var incAtt = new GlideRecord('incident');
incAtt.addQuery(current.table_sys_id,incAtt.sys_id);
incAtt.addEncodedQuery('assigned_to=');
incAtt.query();
if (incAtt.next()) {

var group = incAtt.assignment_group;

if (incAtt.get(current.table_sys_id)) {

var createB =current.sys_created_on+","+current.sys_created_by+','+incAtt.sys_id;

gs.eventQueue('incident.attachment.add',current,group,createB);

 

 

Mail script:

 

Create a mail script with name "test" using below script:

 

var t = event.parm2;

var k = t.split(",");

var user = new GlideRecord('sys_user');

user.get('user_name',k[1]);

var r= "1. Attachment by: "+user.name;

var cre ="2. Attachment Date: "+k[0];

template.print(r)

template.print(cre)

template.print("3.You can view the attachment by clicking the link ")

var url = "<button style='background-color:blue;border:5px solid black'><a href='your instance_url' "+ "/sp?id=ticket&sys_id="+k[2]+">Take me to the incident</a></button>

template.print(url)

 

use this mail script in notification using below line in body of notification

${mail_script:test}

 

If it helps kindly click on like icon and accept the solution

Hi @siva krishna M2 

 

After use of this script  i got below out put  with no link and when i click on button redirect to not found 

Purushotham1992_1-1707231124359.png

 

 

Business rule:

var incAtt = new GlideRecord('incident');
incAtt.addQuery(current.table_sys_id,incAtt.sys_id);
incAtt.addEncodedQuery('assigned_to=');
incAtt.query();
if (incAtt.next()) {

var group = incAtt.assignment_group;

if (incAtt.get(current.table_sys_id)) {

var createB =current.sys_created_on+","+current.sys_created_by+','+incAtt.sys_id;

gs.eventQueue('incident.attachment.add',current,group,createB);

 

 

Mail script:

 

Create a mail script with name "test" using below script:

 

var t = event.parm2;

var k = t.split(",");

var user = new GlideRecord('sys_user');

user.get('user_name',k[1]);

var r= "1. Attachment by: "+user.name;

var cre ="2. Attachment Date: "+k[0];

template.print(r)

template.print(cre)

template.print("3.You can view the attachment by clicking the link ")

var url = "<button style='background-color:blue;border:5px solid black'><a href='your instance_url' "+ "/sp?id=ticket&sys_id="+k[2]+">Take me to the incident</a></button>

template.print(url)

 

use this mail script in notification using below line in body of notification

${mail_script:test}

 

 

Thanks in advance 

Hello @purushothamN599 ,

 

use below updated mail script and use above business rule

var t = event.parm2;

var k = t.split(",");

var link = "https://instanceid.service-now.com/incident.do?sys_id="+k[2];

var user = new GlideRecord('sys_user');

user.get('user_name',k[1]);

var r= "1. Attachment by: "+user.name;

var cre ="2. Attachment Date: "+k[0];

template.print(r)

template.print("\n");

template.print(cre)

template.print("\n");

template.print("3.You can view the attachment by clicking the link ");

template.print("\n");

template.print('<a href="' + link + '"');
template.print('style="' + backgroundColor + border + color + fontSize + fontFamily + textDecoration + webKitBorder + mozBorder + display + padding);
template.print('">');
template.print(gs.getMessage('Take me to the Incident'));
template.print('</a>');

 

If it helps, Kindly click on like icon and mark it as accepted solution

Hi @siva krishna M2  ,

 

I used this business rule and email script and checked event parm1 and parm2 with this body  but did not get view link and take me to button 

 

Body :

Attachment has been added to Incident

${mail_script:test}

 

out Put : 

Purushotham1992_1-1707296593210.png

 

Business Rule : 

var incAtt = new GlideRecord('incident');
incAtt.addQuery(current.table_sys_id,incAtt.sys_id);
incAtt.addEncodedQuery('assigned_to=');
incAtt.query();
if (incAtt.next()) {

var group = incAtt.assignment_group;

if (incAtt.get(current.table_sys_id)) {

var createB =current.sys_created_on+","+current.sys_created_by+','+incAtt.sys_id;

gs.eventQueue('incident.attachment.add',current,group,createB);
 
Email Script : 

use below updated mail script and use above business rule

var t = event.parm2;

var k = t.split(",");

var link = "https://instanceid.service-now.com/incident.do?sys_id="+k[2];

var user = new GlideRecord('sys_user');

user.get('user_name',k[1]);

var r= "1. Attachment by: "+user.name;

var cre ="2. Attachment Date: "+k[0];

template.print(r)

template.print("\n");

template.print(cre)

template.print("\n");

template.print("3.You can view the attachment by clicking the link ");

template.print("\n");

template.print('<a href="' + link + '"');
template.print('style="' + backgroundColor + border + color + fontSize + fontFamily + textDecoration + webKitBorder + mozBorder + display + padding);
template.print('">');
template.print(gs.getMessage('Take me to the Incident'));
template.print('</a>');

 

 

Thanks in advance