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

Hi @siva krishna M2 

 

I tried above script and pasted same in body(what it will contain ) also and tried testing and checked  preview notification

 

Purushotham1992_0-1707135061126.png

 

 

Thanks in advance 

Hello @purushothamN599 ,

 

Kindly check event logs for parm2 value;

Have u updated the business rule code

 var createB =current.sys_created_on+","+current.sys_created_by;// we are concatenating two variables as single variable using joiner ","

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

 

 

Hi @siva krishna M2 

who will receive :

Purushotham1992_0-1707138880853.png

 

This is body content  : 

Attachment has been added to Incident

${number} - ${short_description}

1. Attachment by: k[1]

2. Attachment Date: k[0];

 

And this is 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;

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


                }

 

Out put : 

Attachment has been added to Incident

-

var t = 2024-02-05 13:09:38,lg794609;

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

1. Attachment by: k[1]

2. Attachment Date: k[0];

 

Thanks in advance

Hello @purushothamN599 ,

 

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)

 

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

${mail_script:test}

Hello @purushothamN599 ,

 

If it helps, kindly click on like icon.