Trigger email notification to a newly created user

mpelyanskiy
Kilo Contributor

Good day,

I'm trying to achieve the following aim - when a new user is being added to the sys_user table, I want to grab his email and send out a notification with access credentials. This is going to run in a scoped application

I've reviewed suggested approach in Email Notification to user on creation of his profile and cancel of Request , but it didn't work for me.

I've set up 2 email notifications - both triggered by the same insert opperation to sys_user table. One template is for test purposes only, the other one contains mail script in it's body:

Dear ${first_name} ${last_name},

A user record has been created for you within ServiceNow.

Please follow these instructions for logging in to the system.

${mail_script:new_user_creds}

The blank one has a pre-set email for recepients, and it works well. But the operational one does not fire at all.

The sys_user_script_1 that I'm using:

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

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

                  /* Optional GlideRecord */ event) {

          template.print("1) Browse to https://" + gs.getProperty("instance_name") + ".service-now.com\n");

template.print("2) Enter your credentials\n");

template.print("User ID: "+current.user_name+"\n");

template.print("Password: "+gs.getProperty("glide.user.default_password")+"\n");

//Set the email address to the user record that was being created

email.addAddress("cc", current.email, current.first_name + " " + current.last_name);

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

The notification preview does What am I missing here???

Thanks in advance.

3 REPLIES 3

mpelyanskiy
Kilo Contributor

In order to doublecheck, I've added following line to the mail script:



template.print("User ID: "+current.email+"\n");



In the notification preview, it showed firstName.lastName@example.com instead of an email I've input to the respective field on the form.



Could this be the issue? If so - how can I override it?



Thanks much.


Try with this,



template.print('1) Browse to <a href="https://'+gs.getProperty("instance_name")+'.service-now.com">\n');


template.print("2) Enter your credentials\n");


template.print("User ID: "+current.user_name+"\n");


template.print("Password: "+gs.getProperty("glide.user.default_password")+"\n");


//Set the email address to the user record that was being created


email.addAddress("cc", current.email, current.first_name + " " + current.last_name);


Hi, Balaji



Thanks for the new script - I see you've modified 1st lane only? Am I correct.



With this updates script I started to receive emails to one of my emails. But couple of things that I'm concerned about:



1. In your script, seems that only lane 1 was modified? In Notification preview it's displayed with the <a href=> tag, which doesn't seem correct;


2. The email's I'm getting don't have any subject or body, despite the fact that a template is set up with both items present;


3. When I input a different email (@gmail.com mailbox I have as a secondary email box) - the email is not fired there.



Any thoughts you have on the issues ?



Thanks in advance.