locating getmygroup() function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 09:42 AM
Good morning community.... I would like to create/use the same idea that is used in the getmygroup() function however I cant find the function for review. Would any happen to know where this function is and how would i review its full syntax...
Please advise
Thank you for you assistance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 11:14 AM
Gwen, this function is basically just leveraging the gs.getUser API:
http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0
It is exposed as a Global business rule which allows it to be called from anywhere including reference qualifiers, condition fields, etc.
If you can describe your use case a little more the community may be able to help you come up with a solution. There are many features at your disposal to help run a function to get back data so understanding where your function will be called to pass in a project number. For example is this from a list, a project record, report?
Please mark any post helpful so others reading can benefit from the answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 11:46 AM
Ok Michael thanks for your response
Thank you for responding
The requirements are:
Need to create one dashboard which will be dynamically showing the result based on the login user
I Need to create a dashboard which will dynamically show the project users have access to based on the login user.
I thought to create a routine that filters the project via Element security such as identified in the following screenshot
The code Ive created is
but it doesn't seem to be working
function getMyProjectRoles() {
var roles = new GlideRecord('sys_user_has_role');
var u = gs.getUser().getRecord().getValue('user_name');
roles.addQuery('user_name', u );
roles.query();
while(roles.next()){
if(roles.user.user_name==u){
if(roles.role.name='Spanish' || roles.role.name=='admin'){
answer = '10848fb66f20d2004a07211bbb3ee444';// dropdown should display Spanish which is the project name
return answer;
}
if(roles.role.name==English' || roles.role.name=='admin') ||{
answer = '10848fb66f20d2004a07211bbb3ee444';// show English which is the project name
return answer;
}
}}
}
The goal
Please advise
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 12:51 PM
Thank you for the clarification. Create a new business rule against the Global table similar to the one I pointed you to earlier and then add in the code below. I refactored your code
- I am using the out of the box getRoles() function that will provide a comma separated list of roles that the user has.
- I use the JavaScript indexOf() function to see if your role is within that string.
- As mentioned in the comment your role names look "suspect" as roles usually have no spaces in them so please verify those names.
- Notice that I also create an answer array that I can push multiple SysID's to as I would assume the user could see multiple projects. You code would have only shown one.
- Finally I pass that array as a string back.
function getMyProjectRoles() {
var answer = [];
var roles = gs.getUser().getRoles(); //this will provide a list user roles. Your names in your code don't look like actual role names so check that.
if (roles.indexOf('111 Project Manager') > -1 || roles.indexOf('admin') > -1 || roles.indexOf('Corporate Executives') > -1) {
answer.push('10848fb66f20d2004a07211bbb3ee444'); //Philadelphia Tickets
}
if (roles.indexOf('112 Phila Other PM') > -1 || roles.indexOf('admin') > -1 || roles.indexOf('Corporate Executives') > -1) {
answer.push('10848fb66f20d2004a07211bbb3ee444'); // whatever name
}
return answer.toString();
}
So from here you still call it via the same mechanism of javascript: getMyProjectRoles()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 12:56 PM
Thank you so much Michael I will try the code you've suggested
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 07:42 AM
Good morning Michael Thank you for your help I applied your code and ran it in the script background and received results however when I add the code to the business rules and run my dashboard as another user there are not projects to select... attached are screenshots that hopefully will help with determining what might be the issue
But as I log into the dashboard as another user I do not get any project although this user is assigned to the roles.
Please Please advise
Thank you for your assistance