UI action condition for list field

eliana_wise
Tera Contributor

Hi,

I need help with the UI action condition to check the users that are part of the groups listed in the field( type is list).

This is the condition I wrote, but it doesn't work.

current.u_implementation_group.toString.indexOf(''+gs.getUserId())!=-1|| gs.hasRole('cmc') && new ChangeRequestStateHandler(current).isNext("implement")

This is the field that I was mentioning earlier; this field is dynamic, and it get's the values from business service.

field.PNG

1 ACCEPTED SOLUTION

Looks like I forgot to add current in the condition. What it should be is:


new groupUtils().isMemberAny(current.u_implementation_group, gs.getUser())



Since I did not test the script, you could try running the function call in scripts background. Just be sure to get the sys_id of a record you want to test, as well as the user you are impersonating. I am guessing that this is part of a Change Request [change_request], so I have created this sample you can use to test:


var current = new GlideRecord('change_request');


current.get('TheSys_IdOfTheRecordHERE');


var usrObject = gs.getUser(); //Me


usrObject.getUserByID( ­'abel.tuter'); //Another user to test with;


var chk =   new groupUtils().isMemberAny(current.u_implementation_group, usrObject);


gs.print(chk);



Hopefully there are not any errors in the script itself, otherwise you could separate out the actual function and test it in Scripts - Background:


var current = new GlideRecord('change_request');


current.get('TheSys_IdOfTheRecordHERE');


var usrObject = gs.getUser(); //Me


usrObject.getUserByID( ­'abel.tuter'); //Another user to test with;


var chk =   isMemberAny(current.u_implementation_group, usrObject);


gs.print(chk);



function isMemberAny(grpString, myUsrObject) {


//       isMemberAny: function(grpString, myUsrObject) {


              var retValue = false;


              if (grpString == '') {


                      return retValue;


              } else {


                      grpArray = grpString.split(',');


                      for (var i=0; i < grpArray.length; i++) {


                              var chkMember = myUsrObject.isMemberOf(grpArray[i]);


                              if (chkMember) {


                                      retValue = true;


                              }


                      }


                      return retValue;


              }


//       },


}




This should at least let you know if the function is working as expected. Hopefully the other portions of the UI Action condition are not being true and causing it to show.


View solution in original post

5 REPLIES 5

Looks like I forgot to add current in the condition. What it should be is:


new groupUtils().isMemberAny(current.u_implementation_group, gs.getUser())



Since I did not test the script, you could try running the function call in scripts background. Just be sure to get the sys_id of a record you want to test, as well as the user you are impersonating. I am guessing that this is part of a Change Request [change_request], so I have created this sample you can use to test:


var current = new GlideRecord('change_request');


current.get('TheSys_IdOfTheRecordHERE');


var usrObject = gs.getUser(); //Me


usrObject.getUserByID( ­'abel.tuter'); //Another user to test with;


var chk =   new groupUtils().isMemberAny(current.u_implementation_group, usrObject);


gs.print(chk);



Hopefully there are not any errors in the script itself, otherwise you could separate out the actual function and test it in Scripts - Background:


var current = new GlideRecord('change_request');


current.get('TheSys_IdOfTheRecordHERE');


var usrObject = gs.getUser(); //Me


usrObject.getUserByID( ­'abel.tuter'); //Another user to test with;


var chk =   isMemberAny(current.u_implementation_group, usrObject);


gs.print(chk);



function isMemberAny(grpString, myUsrObject) {


//       isMemberAny: function(grpString, myUsrObject) {


              var retValue = false;


              if (grpString == '') {


                      return retValue;


              } else {


                      grpArray = grpString.split(',');


                      for (var i=0; i < grpArray.length; i++) {


                              var chkMember = myUsrObject.isMemberOf(grpArray[i]);


                              if (chkMember) {


                                      retValue = true;


                              }


                      }


                      return retValue;


              }


//       },


}




This should at least let you know if the function is working as expected. Hopefully the other portions of the UI Action condition are not being true and causing it to show.