- 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-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-05-2024 06:25 AM
I would recommend using flow designer for this with low-code/no-code solution
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader