best scripting practice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 11:20 AM
hi all ,
Active (checkbox) field ----> if true add user to a system support group.
-----> if false remove user from a Group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 11:46 AM
Optimize usually means to make something work BETTER.
I'm not 100% sure "this" works at all.
What are you running? A business rule? Background script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 10:47 PM
a business rule

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 10:52 PM - edited 10-14-2024 10:53 PM
Hello
Considering your BR is on sys_user table, please check the below code and see if this helps -
(function executeRule(current, previous /*null when async*/) {
if (!current.active) {
var userRecord = new GlideRecord('sys_user_grmember');
userRecord.addQuery('user', current.sys_id);
userRecord.addQuery('group', '0a52d3dcd7011200f2d224837e6103f2');
userRecord.query();
if (userRecord.hasNext()) {
while (userRecord.next()) {
userRecord.deleteRecord();
}
} else {
userRecord.initialize();
userRecord.user = current.sys_id;
userRecord.group = '0a52d3dcd7011200f2d224837e6103f2';
userRecord.insert();
}
}
})(current, previous);