Dynamic email links dependent on recipient role?

J Shone
Kilo Expert

As a system admin, i need the links included in notification sent out via email updated so that non-it users are directed to the portal whereas IT users are directed to the backend tool 

 

Links in email notifications currently direct the user to the tool/UI.  e.g. link button in resolve email> https://service-now.com/incident.do?sys_id=cce3ef25db12d010d282342dfdsfds3f3961968&sysparm_stack=incident_list.do?sysparm_query=active=true  

A better url to use for non-util users might be:      

https://service-now.com/nav_to.do?uri=%2Fincident.do%3Fsys_id%3Dcce3ef25db12d010d2823fdsfds423f3961968  

This would direct a non-IT user to the Portal.    

It is possible on mail scripts to check the user role, e.g.  if(gs.getUser().getUserByID(current.opened_by).hasRole('itil'))  And then generate a link to the SN tool for itil users, but for other users take them to a portal view.  

 

Problem:

The recipients of a single notification might have different roles, e.g.:

 

Joe Blogs - itil user

John Doe - non-itil user

 

Question: How would you generate a link in an email that would work for both user types and direct each to the right landing point?

 

- multiple notifs

- two links in email (one to portal one to to tool)

- mail script to email each recipient individually

- redirect

- other

 

1 ACCEPTED SOLUTION

So the group has the group email filled in and you send it to that? If the email address on the group is empty, it will send out an individual email to all group members. Then the script will work.

If you send out the email to the Group email address. Then only one email goes out and you should indeed set up redirect for the end users. You can refer to this:

Create the system property "glide.entry.loggedin.page_ess" if it does not already exist and set the value to "/sp". That should always redirect the ess users to your Service Portal.

https://hi.service-now.com/kb_view.do?sysparm_article=KB0714506

View solution in original post

13 REPLIES 13

Willem
Giga Sage
Giga Sage

You can try this in the mail script:

if(gs.getUserByID(current.opened_by).hasRole('itil')){
    template.print('Link: <a href="https://'+ gs.getProperty('instance_name')+'.service-now.com/incident.do?sys_id='+ gr.sys_id +'&sysparm_stack=incident_list.do?sysparm_query=active=true">click here</a>');
}
else{
    template.print('Link: <a href="https://'+ gs.getProperty('instance_name')+'.service-now.com/incident.do?sys_id='+ gr.sys_id +'">click here</a>');}}
}

Thanks Willem but this issue is you can have itil role recipients and non-itil recipients on the same notif....Is there a way to ensure each user is directed to the right view (portal v tool)?

It is the same mail. But depending on the role will add the different link. You can add this script to email like this:

Add the script to a new email script:

find_real_file.png

find_real_file.png

Add the script, it should look like this:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
										   /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
										   /* Optional GlideRecord */ event) {

	if(gs.getUserByID(current.opened_by).hasRole('itil')){
		template.print('Link: <a href="https://'+ gs.getProperty('instance_name')+'.service-now.com/incident.do?sys_id='+ gr.sys_id +'&sysparm_stack=incident_list.do?sysparm_query=active=true">click here</a>');
	}
	else{
		template.print('Link: <a href="https://'+ gs.getProperty('instance_name')+'.service-now.com/incident.do?sys_id='+ gr.sys_id +'">click here</a>');
	}


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

 

Then in your email/notification itself just add the following to the place where you want the link to appear:

determine_link is the name of the Email Script we just created. If you created with a different name, use that.

${mail_script:determine_link}

 

Also please see:

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/script/server-scripting/concept/...

To link to the portal it might be best to use:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */ event) {

        if(gs.getUserByID(current.opened_by).hasRole('itil')){
            template.print('Link: <a href="https://'+ gs.getProperty('instance_name')+'.service-now.com/incident.do?sys_id='+ gr.sys_id +'&sysparm_stack=incident_list.do?sysparm_query=active=true">click here</a>');
        }
        else{
            var url = '<a href="' + gs.getProperty('glide.servlet.uri') + 'sp?id=ticket&table=' + current.sys_class_name + '&sys_id=' + current.sys_id + '">Link</a>';
           template.print(url);
        }


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