- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 07:13 AM
Hi All,
All users are redirected to Self Service View. I do have a view rule as shown below. However, still the user is having self service view selected as default.
var user = gs.getUserID();
var users = new GlideRecord('sys_user_has_role');
users.addQuery('user', user);
users.addEncodedQuery('role=319665eddb695b0005d2147a3a96194d');
users.query();
while(users.next()){
gs.addInfoMessage("changing the View");
view = 'test_view';
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 09:30 AM
Checkout the Global Business Rule named incident functions
In the script you will find a function incidentGetViewName()
Make your coding changes in the function, this function is responsible to redirect you to ess by default
// populate the default value for the caller
function incidentGetViewName() {
if (gs.hasRole("your role name")) {
answer = "YOUR_VIEW_NAME_HERE";
return answer;
}
if (gs.hasRole("itil"))
return;
if (view.startsWith("ess"))
return;
if (view == "sys_ref_list")
return;
answer = "ess";
}
Reference:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 09:07 AM
Everything looks good not sure why its not working for you, make sure there are no other view rules that are in conflict with this view rule.
Also, no spaces and uppercase letters in the view rule name that you are assigning to the answer variable.
Note:- gs.hasRole returns true all the time for admin. So make sure when you test this view rule you impersonate or login as the end user. gs.hasRole intakes the role name as the parameter, not the sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 09:23 AM
Hi aman,
i AM passing string not sys_id. There are no other views on the table. the view name is just single word.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 09:24 AM
Also, if I make that view riule inactive, it re-directs to ess view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 09:30 AM
Checkout the Global Business Rule named incident functions
In the script you will find a function incidentGetViewName()
Make your coding changes in the function, this function is responsible to redirect you to ess by default
// populate the default value for the caller
function incidentGetViewName() {
if (gs.hasRole("your role name")) {
answer = "YOUR_VIEW_NAME_HERE";
return answer;
}
if (gs.hasRole("itil"))
return;
if (view.startsWith("ess"))
return;
if (view == "sys_ref_list")
return;
answer = "ess";
}
Reference:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 09:18 AM
Have you checked the below thread.
https://community.servicenow.com/community?id=community_question&sys_id=db1849e4db44a780a39a0b55ca96192c&view_source=searchResult
Thanks