How to skip notification for users who is having only snc_internal role

raj149
Giga Guru

Hello Experts,

 

var gr = new GlideRecord("sys_user");

 

gr.addEncodedQuery('last_loginRELATIVEGT@dayofweek@ago@77^last_loginRELATIVELT@dayofweek@ago@75^active=true');


gr.query();

while (gr.next()) {

gs.eventQueue('User_inactive_76_days_reminder', gr, gr.email, gr.user_name);

}

 

The above scheduled script will send a remainder notification at 76th day to notify user.

 

Now requirement is 

If user is having only snc_internal role then I want to skip that users .

How can we do that by using existing script.. 

 

 

Thanks in advance,

 

Best Regards,

Raj

5 REPLIES 5

Harish Bainsla
Kilo Patron
Kilo Patron

// Query user records with the "snc_internal" role
var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('active=true^roles=snc_internal^rolesNOTLIKE%3D%5Eu_'); // Exclude users with other roles
userGr.query();

// Loop through the users
while (userGr.next()) {
gs.log('Skipping notification for user with only snc_internal role: ' + userGr.getDisplayValue('user_name'));

// You can put your skip notification logic here
// ...
}

Hello @Harish Bainsla 

 

I am learner,

 

Could you please ping me exact script that will helpful for me.

I want to send a reminder notification on exact 76th day . In that i want to skip only having snc_internal users for remaining users i want to send notification.

 

Best Regards,

Raj 

 

 

var gr = new GlideRecord("sys_user");

gr.addEncodedQuery('last_loginRELATIVEGT@dayofweek@ago@77^last_loginRELATIVELT@dayofweek@ago@75^active=true');
gr.query();

while (gr.next()) {
// Check if the user has only the "snc_internal" role
var hasSncInternalRole = false;
var userRoles = gr.getRoles();

for (var i = 0; i < userRoles.length(); i++) {
var role = userRoles.get(i);
if (role == 'snc_internal' && userRoles.length() === 1) {
hasSncInternalRole = true;
break;
}
}

// If the user doesn't have only the "snc_internal" role, send the reminder
if (!hasSncInternalRole) {
gs.eventQueue('User_inactive_76_days_reminder', gr, gr.email, gr.user_name);
}
}

Hello @Harish Bainsla 

 

Thanks for your help.

 

Above script is not working for me ,  is there any way to Glide again sys_user_has_role table 

 

Best Regards,

Raj