- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 05:24 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 01:59 AM
Hi @Rakesh40
Please configure your Business Rule as below and it should work :
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 06:56 AM
Hi @Rakesh40 ,
Please review the logic again, also share the BR running on which table [ sys_user ] or [ sys_user_grmember ].
Second, the script code has If condition, so it will execute for one user ( as per default order by result set ) only, and if we replace the if with while then it will execute for all group (ALL-VIP-USERS) user every time when the said condition trigger.
What's the trigger point for VIP flag set/re-set. Explain the business case here, so we can correct this code. Share the screen shot of BR front page.
-Thanks,
AshishKMishra
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 12:24 AM
My requirement is :
The VIP tag needs to set to "True" when User is added to the group "ALL-VIP-USERS" and when user is removed from the group "ALL-VIP-USERS", the VIP tag should be set to "False".
Screenshot : the BR running on [sys_user_grmember] table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 06:17 AM
Hi @Rakesh40 ,
Follow the code shared by @Chetan Mahajan in two separate BR with "when to run" condition for group "ALL-VIP-USERS", so BR will execute only if there is any insert/delete happen in sys_usr_grmember table for this group only.
-Thanks,
AshishKMishra
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 01:20 AM
Hello Rakesh,
You can create 2 BR on sys_user_grmember
1. After insert -> condition Group - is - ALL-VIP-USERS
Script :
(function executeRule(current, previous /*null when async*/) {
var userSysID = current.user;
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id',userSysID);
userGR.query();
if(userGR.next()){
userGR.vip ='true';
userGR.update();
}
})(current, previous);
2. Before Delete -> Condition Group - is - ALL-VIP-USERS
Script :
(function executeRule(current, previous /*null when async*/) {
var userSysID = current.user;
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id',userSysID);
userGR.query();
if(userGR.next()){
userGR.vip ='false';
userGR.update();
}
})(current, previous);
Please consider marking it as correct and helpful if you find the information beneficial