- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2024 07:53 PM
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.]
Event and email Notification created on incident table
Business rule created on Attachment table
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 03:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 06:21 AM
Hello @Purushotham1992 ,
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 06:53 AM
After use of this script i got below out put with no link and when i click on button redirect to not found
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 11:19 PM
Hello @Purushotham1992 ,
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 01:04 AM
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 :
Business Rule :
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