Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Notification for user creation

jobin1
Tera Expert

in ServiceNow whenever a user profile is created we have to send a notification to that user and it includes the user id, password (which is set at the time of creation), and the ServiceNow URL ->https:/.service-now.com
how we can achieve this?

10 REPLIES 10

iam getting the below log  rest all logs looks good

 gs.log('Failed to send notification email to ' + current.email);

Hi @jobin1,

 

  • Email Configuration Issues:

    • Verify your ServiceNow instance's email configurations under System Properties > Outbound Mail. Ensure that SMTP settings are correctly configured and that there are no connectivity issues with your mail server.
  • Email Format and Recipient Address:

    • Double-check that current.email contains a valid email address in the correct format (e.g., user@example.com). If current.email is blank or malformed, the email sending will fail.
  • ServiceNow Email Logs:

    • Check the ServiceNow email logs (System Logs > Email Logs) for more detailed error messages or warnings related to the failed email attempts. This can provide insights into specific issues such as delivery failures or rejected emails.
    • Also check below script :

 

 

(function executeRule(current, previous /*null when async*/) {
    // Log to track the flow
    gs.log('Executing Business Rule for new user creation. User Name: ' + current.user_name + ', Email: ' + current.email);

    if (current.email) {
        // Trigger the custom event
        gs.eventQueue('user.creation.notification', current, current.user_name, '');

        // Send notification
        var email = new GlideEmailOutbound();
        email.setSubject('Your ServiceNow Account Details');
        email.setBodyFromNotification('ec3bac3983578a10b7594d226daad371'); // Replace with your actual notification sys_id
        email.addRecipient(current.email);
        var sent = email.send();

        if (sent === true || sent === 'true') {
            gs.log('Notification email sent successfully to ' + current.email);
        } else {
            gs.log('Failed to send notification email to ' + current.email + '. Error: ' + sent);
        }
    } else {
        gs.log('No valid email address found for user ' + current.user_name);
    }
})(current, previous);

 

Thank you, please make helpful if you accept the solution.

I am getting the below log  rest the logs looks good and i tried giving my ID static in whom to receive then I got the mail attaching a screenshot 
now i think recipient-related information is not getting in the notification from BR i guess
  

 gs.log('Failed to send notification email to ' + current.email);
jobin1_0-1720605544537.png

 



jobin1
Tera Expert

my case is on user creation and how to get the real-time password as well

That all depends on how the password is set. With SSO they already know their password. If you are setting a default password on every user creation, you can just add that as text.

If you are just letting ServiceNow set the passwords, it would be best to have the 'reset password' functionality activated and let users login on that page, so they can create their own. 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark