- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 02:46 AM
Hi,
I'm trying to achieve an view rule that accomplishes the following demand:
- (gs.hasRole('real_estate_agent') && current.assignment_group == 'Real Estate'){
answer = "real_estate";}
Tickets(sc_request) that are assigned to the Real Estate assignment group and their agents should have their own view.
Is this possible to accomplish? (I know that the use of current doesn't work in view rules)
Best Regards.
Andreas
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 04:01 AM
Try this, i'm using something similar elsewhere to reference fields on the current form to set the view:
(function overrideView(view, is_list) {
var url = gs.action.getGlideURI().getMap();
var sysId = url.get('sys_id');
var gr = new GlideRecord('sc_request');
if (gr.get(sysId)) {
if(gs.hasRole('real_estate_agent') && gr.assignment_group.getDisplayValue() == 'Real Estate'){
answer = 'real_estate';
}
}
})(view, is_list);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 02:54 AM
Hi Andreas,
yes current won't work in view rules script;
you can give condition like assignment group is Real Estate but you cannot check for the role
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 03:47 AM
I don't know how you are using this script. However I find an issue in the commend. For assignment group you should check the sys_id of assignment group. So your command should be like this
(gs.hasRole('real_estate_agent') && current.assignment_group == 'sys_id of Real Estate group'){
answer = "real_estate";}
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 04:01 AM
Try this, i'm using something similar elsewhere to reference fields on the current form to set the view:
(function overrideView(view, is_list) {
var url = gs.action.getGlideURI().getMap();
var sysId = url.get('sys_id');
var gr = new GlideRecord('sc_request');
if (gr.get(sysId)) {
if(gs.hasRole('real_estate_agent') && gr.assignment_group.getDisplayValue() == 'Real Estate'){
answer = 'real_estate';
}
}
})(view, is_list);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 04:29 AM
Thanks, works as expected!