How to get the current notification value

richardjparry
Tera Contributor

Hi all,

I need a way to query if the current record the notification is working of off, matches the notification selected in the ticket.

i.e. INC0000001 has the customer facing template selected (via a reference field), and the event that notification is build on is triggered.

I need all the notifications running against that trigger to check if that notification is the one set in the ticket, answering true if so.

Once I can get hold of the notification I can see if it matches, without having to register numerous event names.

answer = (current.getUniqueValue() === this.getUniqueValue()) ? true : false;

But getting the keys of 'this' doesn't reveal anything obvious to use.

Any way of getting the notification object/sys_id from within the notification script?


Thanks

4 REPLIES 4

marcguy
ServiceNow Employee
ServiceNow Employee

The unsubscribe link uses email_action.sys_id to identify a notification (or email_action.name for it's title)



template.print('<a href=""' + gs.getProperty('glide.email.override.url')   + '?uri=unsubscribe.do?sysparm_notification=' + email_action.sys_id   + '"">Click here to Unsubscribe</a> from the ""' + email_action.name + '"" Notification<br />\n');


Mmm promising, and good to know for future, but email_action isn't available in the notifications.


Of the below, only the 1st line will print to the log...



gs.log("RP test pre");


gs.log("RP email_action.sys_id "+email_action.sys_id);


gs.log("RP email_action.sys_id "+email_action);


gs.log("RP test post");


looks like it has to be inside that <mail_script> enclosure to work, so that's probably not going to be any good to you?



http://wiki.servicenow.com/index.php?title=Scripting_for_Email_Notifications#Mail_Script_API&gsc.tab...


I found this discussion on a previous thread here:


https://community.servicenow.com/thread/148987



  1. <mail_script>  
  2. //get the sysevent_email_action record  
  3. gs.log("email_action.getUniqueValue() = " + email_action.getDisplayValue() + " : " + email_action.getUniqueValue(), "EMAIL");  
  4.  
  5. //get the sysevent record that fired this notification  
  6. gs.log("event.getUniqueValue() = " + event.getDisplayValue() + " : " + event.getUniqueValue(), "EMAIL");  
  7. </mail_script>  

Oh sorry think I need to be clearer; I need to get the value in the condition script section.


That way I can control whether the notification runs or not.