When the user account is Locked in user table and if that user tries to send an email

Yougander patel
Tera Contributor

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);

1 ACCEPTED SOLUTION

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.

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

View solution in original post

6 REPLIES 6

Ratnakar7
Mega Sage
Mega Sage

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

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

Teja11
Giga Guru

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

template.print(''Your account has been locked. Please contact IT to unlock your account.");   //message

                               

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.

Nayan  Dhamane
Kilo Sage
Kilo Sage

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.

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.