Email notification - Check recipients role on all emails sent

s_sterner
Mega Guru

Hi SNOW Dev Community,

Question around email notifications that get sent referencing a records number. So what I am doing is whenever an email is getting sent out that includes my notification script the script is checking the users role and spitting out a template print based on if the user has the itil role or not. I am only using this when I go to reference a records number.

Scenario -
Incident notification goes out with incident details. The details include the incident number. I want the number be just the number if the user does not have an ITIL role and a URI_REF if the user does have an ITIL role.

<tr><th>Incident #:</th>

<td>${mail_script:incident.link.role.check}</td>

</tr>

<tr><th>Opened At:</th>

<td>${opened_at}</td>

</tr>

<tr><th>Opened By:</th>

<td>${opened_by}</td>

</tr>

Notification Script -

attachLink();

function attachLink() {

    //Check for requestor's role

    var userObj = gs.getUser().getUserByID(current.caller_id);

    if (userObj.hasRole('itil')) {

              template.print('${URI_REF}');

    }

    else {

  template.print('${number}');

    }

}

Instead of making it so that the script checks for a specific field, in this case the caller_id, can I make it so that it just checks whomever the email is getting sent to? I only need this check to happen when my notification includes a ${number} or ${URI} reference.

Thoughts?

Thanks in advance,

Sean

5 REPLIES 5

Hannah C
Giga Expert