Set the "VIP" flag to false when user is Not part of the group.

Rakesh40
Tera Contributor

Hello,

How to set the "VIP" flag to false on user record when user is not part of the group "ALL-VIP-USERS"?

I tried to write the Business rule script which is not working:

 

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

    var grp = new GlideRecord("sys_user_grmember");
    grp.addQuery('group', 'b54fed9593233110b9bff7718bba10ce'); //ALL-VIP-USERS
    grp.query();
    if (grp.next()) {
        gs.info(grp.user);
        var gr_user = new GlideRecord("sys_user");
        gr_user.addQuery("sys_id", grp.user);
        gr_user.query();
        while (gr_user.next()) {
            gr_user.vip = 'true';// To set the VIP true
            gr_user.update();
        }

    } else {
        gr.initialize();
        gr_user.vip = 'false';//  To set the VIP false
        gr_user.update();
    }
})(current, previous);

 Thanks

1 ACCEPTED SOLUTION

Amit Verma
Kilo Patron
Kilo Patron

Hi @Rakesh40 

 

Please configure your Business Rule as below and it should work :

 

AmitVerma_0-1704448660381.png

 

AmitVerma_1-1704448691527.png

 

Business Rule Script :

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

	// Add your code here
	var userSysID = current.user;
	var userGR = new GlideRecord('sys_user');
	userGR.addQuery('sys_id',userSysID);
	userGR.query();
	if(userGR.next()){
		var vipStatus = userGR.vip;
		if(vipStatus){
			userGR.vip = 'false';
			userGR.update();
		}
		else
			{
				userGR.vip ='true';
				userGR.update();
			}
		
	}

})(current, previous);

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

6 REPLIES 6

Amit Verma
Kilo Patron
Kilo Patron

Hi @Rakesh40 

 

Please configure your Business Rule as below and it should work :

 

AmitVerma_0-1704448660381.png

 

AmitVerma_1-1704448691527.png

 

Business Rule Script :

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

	// Add your code here
	var userSysID = current.user;
	var userGR = new GlideRecord('sys_user');
	userGR.addQuery('sys_id',userSysID);
	userGR.query();
	if(userGR.next()){
		var vipStatus = userGR.vip;
		if(vipStatus){
			userGR.vip = 'false';
			userGR.update();
		}
		else
			{
				userGR.vip ='true';
				userGR.update();
			}
		
	}

})(current, previous);

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Ankur Bawiskar
Tera Patron
Tera Patron

@Rakesh40 

I would recommend using flow designer for this with low-code/no-code solution

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader