Sending notifications to the sender

Dubz
Mega Sage

Hi,

I have a notification set up to send to anyone who is emailing a closed Incident saying words to the effect of 'this incident is closed, click here to raise a new one'. The trouble i'm having is getting this to send back to whoever emails the closed ticket.

I don't want to spam everyone on the watchlist just because 1 guy decided to try and resurrect an old ticket so i'm trying to send to the 'updated by' field. The problem with this is that the updated by field isn't referencing the user table, it's just displaying the user ID which in our case, is not an email address.

Even if we can change that field to reference the user table, if someone emails in who is not in the user table, they won't receive the notification telling them the ticket is closed.

Is there a way to pull out the senders address from an incoming email and send the notification to that address?

Cheers

Dave

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi David,



Yes, you have two choices as you noted. The first is to use the user id in the sys_updated field and do a lookup from the sys_user table (eg. something like this)



var user = GlideRecord('sys_user');


if (user.get('user_name', current.sys_updated_by)) {


        // user found - do something here


}



The issue, as you noted is that the record may not be updated by someone in the sys_user table, in that case you would need to trigger the message from the incoming mail and use the from address as the to address.



Take a look at triggering email by event (using the gs.eventQueue() method) and send the recipient's address as one of the two parameters (parm1 or parm2) in that call. The notification record has a field that allows you to use one of those parameters as the address - you need to click the Advanced view link to see that field after selecting to send by event (not record inserted or updated.)



Events and Email Notification - ServiceNow Wiki


View solution in original post

5 REPLIES 5

Chuck Tomasi
Tera Patron

Hi David,



Yes, you have two choices as you noted. The first is to use the user id in the sys_updated field and do a lookup from the sys_user table (eg. something like this)



var user = GlideRecord('sys_user');


if (user.get('user_name', current.sys_updated_by)) {


        // user found - do something here


}



The issue, as you noted is that the record may not be updated by someone in the sys_user table, in that case you would need to trigger the message from the incoming mail and use the from address as the to address.



Take a look at triggering email by event (using the gs.eventQueue() method) and send the recipient's address as one of the two parameters (parm1 or parm2) in that call. The notification record has a field that allows you to use one of those parameters as the address - you need to click the Advanced view link to see that field after selecting to send by event (not record inserted or updated.)



Events and Email Notification - ServiceNow Wiki


Thanks Chuck,



So i think i'll try and set up the event method as that should account for all eventualities rather than just occasions when someone in the user table gets in touch.



If i understand you correctly i need to create an event named something like closed.incident.updated and then associate a business rule to run after the record is updated with a script something like below:



if (current.operation() == 'update' && current.state.closed()) {


  gs.eventQueue("closed.incident.updated", current, gs.getProperty("glide.email.user"));


  }



(I'm not sure if that's the right property to get the email address, i've never scripted before so i've just pieced this together from snippets i've found lying about the place!)



Then i set the notification to send when that event is triggered and to send to the address returned in parm1?



Cheers


Dave


Hi David,



You're on the right track. Create an event in the registry (convention is to put the table name first) so something like incident.closed.update.



Then create a notification that reacts to that event



Finally trigger the event from a server side script. A business rule won't have the original "from" email address so you need to do it from the inbound email action (after the script determines that the incident is closed (or active=false)



FWIW, gs.eventQueue() has four arguments. Your call would look something like this:



gs.eventQueue('incident.closed.updated', current, email.from, '');


Hi Chuck,



Thanks a lot for the assistance with this, i created a script action associated with the event which is in turn associated with the notification, is that sufficient to return the data i need? You've mentioned an inbound email action as well, i'm not sure how that fits into the equation.



Cheers


Dave