The CreatorCon Call for Content is officially open! Get started here.

Advanced Notification Condition - Do not send email if member of group

Josh80
Tera Expert

Hello


I have a requirement for a notification when a Request is submitted via Self-Service.


I need the advanced condition to lookup the User's group membership and if is a member of a certain group, do not trigger the email.

I saw this script on another user's question, but I cannot seem to get it to work.   Any suggestions?

So logically - the script should look up the user's group membership and if XXX group is found, then return false and not generate email.

Thanks in advance!

if (!isGroupMember(current.opened_by, 'group here') ) {

      answer = true;

} else {

      answer = false;

}

          var grpMbr = new GlideRecord('sys_user_grmember');

              grpMbr.addQuery('user', userID);

              grpMbr.addQuery('group', groupID);

              grpMbr.query();

              if (grpMBR.next()) {

                      return true;

              } else {

                      return false;

              }

1 ACCEPTED SOLUTION

Hi Josh,



You are getting that error because using a "return" expects you to be using it within a function.   Instead try setting the variable "answer = true;" (or false).



i.e.,


var grpMbr = gs.getUser();


if(grpMbr.isMemberOf('Service Desk')){


      answer = false;


}


else{


      answer = true;


}




However as mentioned earlier, you should be able to skip the "if" statement since isMemberOf() returns a true/false on it's own.   You could just use:



answer = !gs.getUser().isMemberOf('Service Desk');





Just for efficiency's sake.  





Thanks,


-Brian


View solution in original post

15 REPLIES 15

HI - no, unless I'm putting it in the wrong place.



Snap49.png


That's the right place, remove the rest of the script. I also don't think you need that condition Opened by.Company.Name is not


Well actually I need to say if user is NOT a member of a group; normally I would use an '!' in front of is memberof but it's not working.



gs.getUser().isMemberOf('Service Desk')


Hi Josh,



You are getting that error because using a "return" expects you to be using it within a function.   Instead try setting the variable "answer = true;" (or false).



i.e.,


var grpMbr = gs.getUser();


if(grpMbr.isMemberOf('Service Desk')){


      answer = false;


}


else{


      answer = true;


}




However as mentioned earlier, you should be able to skip the "if" statement since isMemberOf() returns a true/false on it's own.   You could just use:



answer = !gs.getUser().isMemberOf('Service Desk');





Just for efficiency's sake.  





Thanks,


-Brian


Brian,



That did it...thank you!   I know I've done it before somewhere else, but I could not remember how to do it for the life of me.   I can do it in ACLs, etc and do it often using isMemberOf.



Thank you!



Also, thanks to Michael who has helped me out on more than one occasion (as well as Pradeep and Srinivas!)