Link email notifications to portal

Christine24
Giga Expert

I am working on notifications for our end users and wanted to start having them point to the portal. I did some researching and found this post: https://community.servicenow.com/community?id=community_question&sys_id=79d187a9db98dbc01dcaf3231f961933

However I am seeing two problems with this and wasn't sure how to fix them:
1. I wanted to use it for two different portals - we have an internal portal and a client facing portal. How do I make sure it works for the appropriate link?

2. When I put the script into my instance I got the error: Email script render error: email script [ service_portal_link ] does not exist

 

Any ideas on how this one?

21 REPLIES 21

I used the script you posted above 🙂

Steven Slocum
Tera Guru

Use some type of IF statement within your notification script based on the users attributes (groups/roles/however you decide which portal they should see), and then pass a script variable into the href.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


/* Optional GlideRecord */ event) {


var portal = 't'; //set default

if(recipient_user.email.toString().indexOf('INTERNAL EMAIL ADDRESS')){
portal = 'sp';
}




   var url = '<a href="' + gs.getProperty('glide.servlet.uri') + portal + '?id=ticket&table=' + current.sys_class_name + '&sys_id=' + current.sys_id + '">' + current.number + '</a>';

   template.print(url);


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

I feel like I was close to that (see my replies)!

So I adjusted it to what you put in but for the Else statement, would I need something like

if(recipient_user.email.toString().indexOf!('INTERNAL EMAIL ADDRESS'))

Not totally necessary since we are already setting the default value of the portal as 't'. So if the user has the internal email address the new portal value will be 'sp', and if not it will continue onward with the default value.

Ahh, I missed that in the code you changed!

I will try it out, thank you. 🙂