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

Tushar
Kilo Sage
Kilo Sage

Hi @raj149 

 

I hope this should help - 

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();

  // Count the number of roles the user has
  var numRoles = userRoles.length();

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

  // If the user only has the "snc_internal" role, skip sending the reminder
  if (!hasSncInternalRole) {
    gs.eventQueue('User_inactive_76_days_reminder', gr, gr.email, gr.user_name);
  }
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar