Adding an 'Unsubscribe' link to an email message

User150433
Tera Guru

Hello,

I wanted to know the NOTIFICATION_MESSAGE_SYS_ID in the link. What is it? Email Notification sys_id?


template.print('' + 'Unsubscribe' + '\n');


Please help...

4 REPLIES 4

User150433
Tera Guru

Kindly help me with what should be put here in place of NOTIFICATION_MESSAGE_SYS_ID:


template.print('' + 'Unsubscribe' + '\n');


andrewmaryville
Kilo Contributor

That field needs the sys_id of the Email Notification (sysevent_email_action) you want to unsubscribe from.

However hardcoding this can cause problems when moving instances, and will not work in templates.
If you use the email script below, it will automatically grab the notification sys_id and instance URL. This comes in handy when you move from dev to test to prod, and you can just copy paste this in the body of any email notification (or template) and you don't have to hard code the sys_id of the notification.



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

The

gs.getProperty('glide.servlet.uri')
gets the 'glide.servlet.uri' system property which contains the full URL for your instance, https://yourcompany.service-now.com/
the

email_action
object is available in mail scrits and contains the GlideRecord for the Email Notification (sysevent_email_action) that is generating the current email.
When a user clicks this link it runs the code on the UI Page 'unsubscribe' which then grabs the Notification sys_id we stuck in the url, and adds a filter to the Notification Preference for the current user for that notification, which unsubscribes them.


dave_greene
ServiceNow Employee
ServiceNow Employee

I've set this up on my calgary instance and it appears that the unsubscribe link is only working for users that are in the admin role. I have ITIL users that can go to my profile and unsubscribe to the notification, but when they click the email link, it will not unsubscribe. If I change the itil user to have the admin role it works.

I'm using the code:

template.print('Click here to Unsubscribe from the "' + email_action.name + '" Notification
\n');


the notification I'm using to test with is incident opened for me, and it's not set to mandatory. Is there a way to make this work with itil users or even a user with no role that gets emails?


Dub Myers
ServiceNow Employee
ServiceNow Employee

In Istanbul and later:


Email unsubscribe