Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

javascript:getMyGroups() not working in business rule

dhathri1
Giga Contributor

Hi All,

current.addQuery('assignment_group','javascript:getMyGroups()'); is not working, Please let me know what is exactly wrong in this.

14 REPLIES 14

dhathri1
Giga Contributor

tried with 'javascript:gs.getMyGroups()' as well


Hello Dhathri,



javascript:getMyGroups() returns a list of group(s), the logged in user is part of. The list may contain more than one group.



How can you query the assignment_group field with a list of groups?



You need to split the list with ",". Then store it in a array and write query like :



current.addQuery('assignment_group',arr[i]);



assuming arr is the array variable and variable "i" is for indexing.



Hope, you would be able to rectify the issue now.



Please mark this reply correct/helpful if it answers your query.



Thanks,


Subhankar


var secGroupStr = gs.getProperty('takeda.incident.securityGroup');


var secGroups = secGroupStr.split(',');




var hideGroups = [];




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


  if (!gs.getUser().isMemberOf(secGroups[i])) {


  hideGroups.push(secGroups[i]);


  }


}




var sec_query;




//Hide Security group incidents unless you are the caller or group member


//gs.log('JDM - ' + hideGroups.join(','));


if (hideGroups.length > 0 && !gs.hasRole('admin') &&


  !gs.hasRole('field_services') &&   gs.isInteractive()) {




  var u = gs.getUserID();




  current.addQuery('assignment_group','NOT IN',hideGroups.join(',')).addOrCondition('assignment_group','');




  //current.addQuery("caller_id", u).addOrCondition("opened_by", u);



} else if (hideGroups.length > 0 && !gs.hasRole('admin') &&


      gs.hasRole('field_services') &&   gs.isInteractive()) {




  var u = gs.getUserID();


  current.addQuery('assignment_group','NOT IN',hideGroups.join(','));


  //current.addOrCondition("caller_id", u).addOrCondition("opened_by", u);


  current.addQuery('assignment_group','javascript:getMyGroups()');



} else if (gs.hasRole('field_services') && !gs.hasRole('admin') &&   gs.isInteractive()) {


  //Only show field services their groups work.




  current.addQuery('assignment_group','javascript:getMyGroups()');


  current.addQuery('assignment_group','!=','');


}






if (!gs.hasRole("itil") && !gs.hasRole("incident") && !gs.hasRole("field_services") && !gs.hasRole("problem") && !gs.hasRole("change") && !gs.hasRole("knowledge") && !gs.hasRole("release_v2_admin") && gs.isInteractive()) {


  var u = gs.getUserID();


  var qc = current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u);


  gs.print("query restricted to user: " + u);


}





-----


This is the Business rule existing, Could you please help me to correct this


rob_pastore
ServiceNow Employee
ServiceNow Employee

Inside a BR, you don't need the 'javascript:'   prefix.



just gs.getMyGroups()



(i would also right that value to a log and see what it is giving you, as it may not be in the proper format to use)