- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 03:58 AM
When the user account is Locked in user table and if that user tries to send an email to any specific email address then user should an get an email stating that your account is locked.
on user table before insert and update
please verify my code and let me know because the code is not working in bs rule:
Condition : current.user_account_locked_out== true
(function executeRule(current, previous /*null when async*/) {
var email = current.email;
var subject = "Your account is locked";
var message = "Your account has been locked. Please contact IT to unlock your account.";
gs.eventQueue("email.send", current, email, subject, message);
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 10:41 PM
Hello @Yougander patel ,
What is the issue did you check sys_email table if the email was recieved by the ServiceNow instance.
Please share the screenshot of the email log. so that I can assist you further.
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 04:05 AM
Hi @Yougander patel ,
Here is an updated version of the code that includes these additional conditions:
(function executeRule(current, previous /*null when async*/) {
if (current.user_account_locked_out && current.email && !current.notified_locked_out) {
var email = current.email;
var subject = "Your account is locked";
var message = "Your account has been locked. Please contact IT to unlock your account.";
gs.eventQueue("email.send", current, email, subject, message);
current.notified_locked_out = true;
}
})(current, previous);
If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the ✅Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.
Thank you!
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 01:16 AM
Hi Ratnakar,
This Way also
by changing tables. sys_email and user table and added the code and before insert or update
and condtition :current.user_account_locked_out == true
and above code still its not working when i tried to send email to dev ,in return iam unable get notification email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 04:09 AM
Hi @Yougander patel ,
use this in br
gs.eventQueue("email.send", current, email, " ");
to set the subject and message use email script and call that in notification body
email script : example -locked_out // email script name
email.setSubject("your account is locked"); //subjet
call that email script in notification body like-
${mail_script:locked_out}
Regards,
Teja
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 04:19 AM
Hello @Yougander patel ,
As per your requirement when a user sends an email on specific email in Servicenow he should recieve a mail if he is locked out.
The above requirement can be achieved by below steps:
1. Create a notification with required details on 'sys_emai' table.
2. add the below conditions as shown in the screenshot.
3. Select the 'user id' in 'Users/Groups in fields' field in whom to send column.
3. Update the subject and body.
You do not need the script as per my understanding of the requirement.
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.