Location of a javascript

stevelucas
Kilo Expert

Hi,
Please can you tell me the location in Service-Now of the java scripts set up in the gauge "My Work"
There are 2 in the gauge "javascript:gs.user_id()" and "javascript:getMyGroups()".

I wish to creat a new one and just want to see the format.

Thanks

7 REPLIES 7

var ourGroups = gs.getUser().getMyGroups();   // this get my groups where I do belong


// ourGroups is now an array containing sys_id of each group you are a member of



var grpDisplay = '';     // for optimal javascript you should define variable outside of a loop




for ( var i=0; i < ourGroups.size(); i=i+1)   // ourGroups is an array containing sys_id of groups


{


var group = new GlideRecord('sys_user_group'); // Yes, database query


group.get(ourGroups.get(i));                                     // Yes group.addQuery() is also valid, however requires 3 lines of code instead of this one.              


grpDisplay = grpDisplay + group.name + '\r\n';   // Yes, this is building a string of Group names seperated by OS specific (Windows) new line characters


gs.addInfoMessage(grpDisplay);       // Not a system message, but an info message that will appear at the top of the form the user has just loaded. gs.log() would write the output to the logs


}


stevelucas
Kilo Expert

Thanks Abhiram


Just to add that if you are defining new JavaScripts like getMyGroups() the right place for them is in Script Includes and not Global Business Rules.



Also if you are on Dublin then these can be defined in Dynamic Filters Using Filters and Breadcrumbs - ServiceNow Wiki