The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing or Creating a new getMyGroups() function

HunterSWolf
Mega Guru

I was curious to see if anyone had created a new getMyGroups() function and if so how they did so. We are running into issues where we want to get a users groups but we do not want to pull back the parent groups. With the current function it will pull back all of these group. Looking at the business rule where this function resides it would appear that it is calling itself so I can only imagine that it is hard coded.

Thanks,

8 REPLIES 8

marcguy
ServiceNow Employee
ServiceNow Employee

hello, this might help from the SNC Guru site: http://www.servicenowguru.com/scripting/business-rules-scripting/advanced-getmygroups-function/


Thanks for your help and quick response. This helps a lot.


I have a user defined field called Division on my sys_user table, this field is just a reference field back to cmn_department.

I wanted to create a function similar to getMyGroups() & getMyAssignments() to use in filters.

This is not working for me. Here is my getMyDivision business rule:
Name = getMyDivision
table = Global[global]
Client callable = true
Active = true
Script:

function getMyDivision(){

var MyDivision;
var uID = gs.getUserID();

var user = new GlideRecord('sys_user');
user.addQuery('user', uID);
user.query();

while(user.next()){
MyDivision = user.u_division.toString(); //u_division is simply a reference field back to cmn_department
}

return MyDivision;
}


All the other examples (getMyGroups) seem to simply return an array of Strings, where each string is the sys_id. That is what I am basically doing here, but my reports don't seem to work when I use the javascript:getMyDivision()

Is something wrong with my script? I couldn't seem even find the getMyGroups function to look at that code, but did find some reference that makes me believe that is a server side function tied to the User class.

Any help is greatly appreciated!


I think you could simplify this quite a bit. Try using this as the 'getMyDivision' function.



function getMyDivision(){
return gs.getUser().getRecord().getValue('u_department');
}


You're probably better off putting this into a script include instead of a business rule. You can use the same function, just make sure your script include is named 'getMyDivision' to match the name of your function exactly.

Check out this SNGuru post for more ideas on getting user information.

http://www.servicenowguru.com/scripting/user-object-cheat-sheet/