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

Michael Fry1
Kilo Patron

Seems like you could just use isMemberOf to check the group:



var grpMbr = gs.getUser();


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


return false;


else {


return true;


}


Hello Michael



Stupid question - do you know why I'm getting a response of 'Invalid Return" for the return false?


Hi Josh,



You just need to put below line in the advanced condition box. Advanced condition expects a boolean value as a result so the error.



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



thanks


Srini



Mark this response as correct/helpful if does so


Hello Michael



I appreciate your response...but as is, the return is saying invalid no matter what I add to the script.



Can you suggest what I'm doing wrong?
Thanks