accessing notification type from inside an email script

JP56
Kilo Contributor

Hello, 

I've got no way of knowing how to even approach a problem like this.

Say I've got an email script that needs to dynamically change based on what notification it was sent out in.

e.g. a script named metadata

If a "Incident has been assigned to you" notification is sent out, I want to have an if conditional in the JS that prints X.

If a "Incident has been opened on your behalf" note is sent, I want to have the script print Y.

 

The data itself is easy to get, the js is easy to write, but I genuinely have no idea how to access the type of notification sent from within the script itself.

 

If possible, could someone quickly detail how I might find such data in general? As an example, :

/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event

I'm presuming the data is held in the event GlideRecord, but how would I access it? Is there a list of fields in there somewhere?

1 ACCEPTED SOLUTION

Masha
Kilo Guru

I believe email_action gives you access to the notification record (sysevent_email_action table). You should be able to dot-walk to the notification record that is being used for the email from there.

See oob email script called (lines 3 and 26): incident_take_me_to_the_incident for usage example.

find_real_file.png

View solution in original post

8 REPLIES 8

Shrutika Surwad
Kilo Guru

hey ,

if you find my answer correct.

please mark Correct!

 

thanks,

shrutika surwade

Your answer was unfortunately what a quick google pulled up already. Marked helpful to be nice, but it doesn't really answer my question.

 

Your first link is an article by sabell2012 that talks about the email notification pipeline as a whole, but doesn't go into depth on accessing variables in a more complex way than the most basic modifications, and is more a set-up for CSS manipulation in his next article on the subject. It was a very useful article when starting off with modding email scripts and layouts for my company, but isn't much relevant as far as I can tell.

 

Your second link gets very close, but my question is a bit more nuanced, I guess. For example, your second link shows him looking at properties like "sms_alternate" "exclude_delegates" etc etc. How do I find what properties email_action contains in the first place. How do I find what properties GlideRecords contain

 

I could be wrong about both of those, and just be blind and stupid myself, but that's how it seemed.

Thanks For your Helpful

🙂

asifnoor
Kilo Patron

Hi JP,

You can access the notification data using email_action object in the mail script.

Here is how you can do this. To get the name of the notification, you can access

email_action.name

if you want to check by sys_id, then you can access

email_action.sys_id

go to table email_action and you can access any field associated with the notification with email_action.column_name  in the mail script.

sample mail script

(function runMailScript(current, template, email, email_action, event) {
		gs.log("Notification id is "+email_action.sys_id+"---"+email_action.name);
	//write your code here

})(current, template, email, email_action, event);

Mark the comment as a correct answer and also helpful if it answers your question.