Quesion in Business rule

Srini19
Tera Contributor

Hello,

 

How to lock the user Account using business rule script, kinldy Advise.

 

Thanks

Srini

3 REPLIES 3

Robbie
Kilo Patron
Kilo Patron

Hi @Srini19,

 

Can you expand on what you mean by 'lock the user account' please and advise the use case?

Are you wanting to make the field read-only and only editable by some users - example Admins only or certain group members for example?

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

OlaN
Giga Sage
Giga Sage

Hi,

What do you mean exactly, do you want to set a value on a user account through business rule ?

If so, then it's quite easy.

Example below:

var userGR = new GlideRecord('sys_user');
var userID = 'define the specific user you want to update, it should be a sys ID';

if (userGR.get(userID)){
  userGR.setValue('locked_out', true);
  userGR.update();
}

Rajesh Chopade1
Mega Sage

hi @Srini19 

If you want to deactivate the user then have a look bellow script in your BR (before/after)

// Example condition: Lock account if the user's status is set to 'Inactive'
if (current.active) {  // Check if the user is currently active
    current.active = false; // Lock the account
    current.comments = "Account locked by Business Rule"; // Optional comment
}

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh