Setting a checkbox true

William08
Tera Contributor

Hi all,

 

 

 

If the group has itil role or if the group contains admin in the role then the custom check box should be checked else it should be unchecked  through business rule. If anyone have idea on this could you please help

 

Thanks in advance 

 

 

Thanks in advance.

1 ACCEPTED SOLUTION

I would try an after Insert and delete BR on table sys_group_has_role

with condition of

current.role.name.toLowerCase().indexOf('admin') != -1

 

Not fully tested but something like this should work

        var groupCheck = new GlideRecord('sys_user_group');
        if (groupCheck.get(current.group)) {

            if (current.operation() == 'insert') {
                //check the flag and set true if false
                if (groupCheck.customField == false) {
                    gs.info('Group customField was pdated as customField flag is false');
                    groupCheck.customField = true;
                    groupCheck.update();
                }
            }
        }
	
        if (current.operation() == 'delete') {
//need to check all roles related to the group and update the flag only if no other 'admin' role left
            var selfCheck = new GlideRecord('sys_group_has_role');
            selfCheck.addQuery('group', current.group);
            selfCheck.addQuery('role.name', 'CONTAINS', 'admin');
            selfCheck.setlimit(1);
            selfCheck.query();

            if (!selfCheck.next()) {
                gs.info('Group customField updated as no admin roles exist');
                groupCheck.customField = false;
                groupCheck.update();
            } else {
                gs.info('Group customField not updated as an admin role still exists');
            }

        }

 

View solution in original post

6 REPLIES 6

.

Hi, a scheduled job would not be necessary once the BR was in place as it will update the flag when whenever it is necessary. If you want to set the initial flag you can use a background script or fix

script, loop through all groups, then for each group check to see if any related role contains admin, if you find one then flag the group field and move to the next group record.
The basics of the requirement are already covered in the BR code.

Why don't you make a start and post your code so that the community can review and advise (if necessary)