Portal hyperlinks via email

Brendan Hallida
Kilo Guru

Hi all,

We would like to have emails going to the end users contain the portal link to their request / incident.   I am using email notifications.

The actual link that we have is the following:

Incident:

http://<instance>.service-now.com/sp?id=ticket&table=incident&sys_id=22b899754f112240f5333d501310c786

Request:

http://<instance>.service-now.com/sp?id=sc_request&table=sc_request&sys_id=9350c9f14fddee00f5333d501310c715

I have been doing some research, and found a lot pointing towards this wiki entry: Scripting for Email Notifications - ServiceNow Wiki

That entry has helped my understanding, however it is old and is referring to the ESS page.  

With the code that it suggests, it seems to always add incident.do?sysparm_document_key=incident in the code.

For example:

${CMS_URI+sp?id=ticket&table=incident}

https://<instance>.service-now.com/sp?id=ticket&table=incident.do?sysparm_document_key=incident,619dac624f09ea00f5333d501310c769

I know that I am missing something, hopefully someone out there can easily identify it.

Thanks in Advance!

Brendan

1 ACCEPTED SOLUTION

In our own instance I included Service Portal links by using an email notification script, the contents of which looks like:



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


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


/* Optional GlideRecord */ event) {


  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);



I can then reference this in email notifications/templates by: ${mail_script:service_portal_link}



Note: The syntax highlighting looks a little off in the code snippet above, but you get the idea. I also replaced the name of our portal with "sp" to remain consistent with your example above.


View solution in original post

23 REPLIES 23

Try using the script above and put the url of that portal page in this script line.

var url = "https://" + your_instance + ".service-now.com/* CHANGE THIS TO PORTAL NAME or URL WHERE TICKET IS PLACED*" + "&sys_id="+ current.incident;

For approvals, you have to use current.sysapproval.{} instead of current.{} because the 'current' record is in the sysapproval_approver table, and the referenced record is in the 'sysapproval' field.

Old thread, but I ran into this requirement again today. I accomplished with a simple mail script that checks if 'current' is a sysapproval_approver, then builds the URL based on what current is.
In my use case, we are pointing to an AES UI Builder portal, so {where you need to go} for me is --
x/{glide.appcreator.company.code}/{portal path}/{portal page name}/
==============================================================

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

    // if current record is not an approval use current, otherwise use current.sysapproval
    var recordRef = current.sys_id;
    var recordTable = current.sys_class_name;
    
    if (current.getTableName() == 'sysapproval_approver'){
        recordRef = current.sysapproval;
        recordTable = current.sysapproval.sys_class_name;
    }        
        
    var url = '<a href="' + gs.getProperty('glide.servlet.uri') + '{where you need to go}' + recordRef +'/' + recordTable + '">LINK</a>';    
    template.print(url);

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

Romulus Rodrigu
Tera Expert

This article was very helpful, thank you @dhasselquist I just wanted to add that you can also specify the view as well as the page you want the notification to redirect the notification recipient.

 

 

find_real_file.png