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

Yeah, still nothing. It's weird though because when I used that script in the URL it works, but when I switch to this one it doesn't show anything at all.

 

The current notification is on the defect table (which we have exposed to our end users to submit bugs), but ideally I would want to use the email notification script for all of the end-user notifications.

Mike Patel
Tera Sage

try below. I have tested below with my dev instance and it works fine.

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
    var userArrEmail = [];
    var gr = new GlideRecord("sys_user");
    gr.addEncodedQuery('sys_idIN' + email_action.recipient_users);
    gr.query();
    while (gr.next()) {
        userArrEmail.push(gr.email.toString());
    }
    if (userArrEmail.toString().indexOf('example.com')) {
        template.print("IN");
        var url = '<a href="' + gs.getProperty('glide.servlet.uri') + 'sp?id=ticket&table=' + current.sys_class_name + '&sys_id=' + current.sys_id + '">' + current.getValue('number') + '</a>';
        template.print(url);
    } else {
        template.print("OUT");
        var url2 = '<a href="' + gs.getProperty('glide.servlet.uri') + 't?id=ticket&table=' + current.sys_class_name + '&sys_id=' + current.sys_id + '">' + current.getValue('number') + '</a>';
        template.print(url2);
    }
})(current, template, email, email_action, event);