The CreatorCon Call for Content is officially open! Get started here.

Advanced View Rule - hasRole + assignment_group

andreas_holgers
Kilo Expert

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

 

1 ACCEPTED SOLUTION

Dubz
Mega Sage

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);

 

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

palanikumar
Giga Sage
Giga Sage

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";}

 

Thank you,
Palani

Dubz
Mega Sage

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);

 

Thanks, works as expected!