Set boolean variable to true if user is a member of group

Simon41
Giga Contributor

We are importing several groups from our Active Directory. Now we want to set a boolean variable to true if a user is in a group which is starting with "Group_" => e.g Group_A, Group_B. 

How is this possible? After an AD sync - ServiceNow should check if there were members added or removed and set the boolean to true or false.

 

Thank you!

Simon

1 ACCEPTED SOLUTION

Simon41
Giga Contributor

We solved this with 2 Business rules (one for adding and for removing the user). IMPORTANT: Your group needs a role otherwise it will not work with the AD sync.

Content of the "add business rule"

find_real_file.png

(function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", current.user);
gr.query();


while(gr.next()) {
gr.setValue("u_keyuser", "true");
gr.update();
}

})(current, previous);

 

 

View solution in original post

3 REPLIES 3

Sushma R1
Tera Expert

Could you provide some screenshots please 

We have the following field in our sys_user table:

find_real_file.png

We want to set this to true if the user is in the group (synced with Active Directory). If the user is not a member of the group anymore we want to set the value of the variable to false.find_real_file.png

Simon41
Giga Contributor

We solved this with 2 Business rules (one for adding and for removing the user). IMPORTANT: Your group needs a role otherwise it will not work with the AD sync.

Content of the "add business rule"

find_real_file.png

(function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", current.user);
gr.query();


while(gr.next()) {
gr.setValue("u_keyuser", "true");
gr.update();
}

})(current, previous);