Notification for user creation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 12:13 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 12:18 AM
Hello @jobin1,
Please find below the links which will help you to achieve your use case -
If my answer solves your issue, please mark it as Accepted and Helpful based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 12:20 AM
Hi @jobin1,
To achieve sending a notification with user details upon profile creation in ServiceNow, you can follow these steps:
Create an Email Notification:
- Go to System Notification > Email > Notifications.
- Click on New to create a new notification.
- Configure the notification with a meaningful name and description.
Define Notification Content:
- In the notification content, you can use placeholders to dynamically insert user-specific details like User ID, Password, and the ServiceNow URL.
Dear {{recipient.name}},
Your ServiceNow account has been created successfully.
User ID: {{recipient.user_id}}
Password: {{recipient.password}}
ServiceNow URL: https://your-instance.service-now.com
Regards,
ServiceNow Team
3.Associate Notification with User Creation Event:
- You need to associate this notification with the user creation event.
- Navigate to System Definition > Business Rules.
- Find or create a Business Rule that triggers when a new user record (sys_user) is inserted
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', current.sys_id); // current.sys_id represents the newly created user's record
user.query();
if (user.next()) {
// Send notification
var email = new GlideEmailOutbound();
email.setSubject('Your ServiceNow Account Details');
email.setBodyFromNotification('notification_sys_id'); // Use the sys_id of your email notification
email.addRecipient(user.email);
email.send();
}
Thank you, please make helpful if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 02:30 AM - edited ‎07-10-2024 02:31 AM
currently, i am using the below BR and calling notifications via event but i am getting event logs correctly but notifications are not getting
//br //after insert on sys_user
message html in notification
Dear {{recipient.name}},
Your ServiceNow account has been created successfully.
User ID: {{recipient.user_id}}
Password: {{recipient.password}}
ServiceNow URL: https://your-instance.service-now.com
Regards,
ServiceNow Team
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 02:35 AM
Hi @jobin1,
please try 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) {
gs.log('Notification email sent successfully to ' + current.email);
} else {
gs.log('Failed to send notification email to ' + current.email);
}
} else {
gs.log('No valid email address found for user ' + current.user_name);
}
})(current, previous);
Ensure you replace 'ec3bac3983578a10b7594d226daad371' with the correct sys_id of your notification. Also, check your email server settings and logs to ensure there are no issues with outbound emails.
Thank you, please make helpful if you accept the solution.
