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

Need Help accessing fields in View rule script

Brian S5
Kilo Sage

Can basic view rules and advanced view scripts work together, or do i have to combine them into one for the most streamlined way to manage these views ?

I am wondering if someone can assist me with adding to this current view rule script. 

View rules is on change_request

Business requirement

We have a department with a role that needs a certain view, and also another department with a separate role that needs their own view, and if neither apply, we need to default to a different view and im having some difficulty i was wondering if someone could help with. I tried leaving the view script alone, and adding a new view rule with a basic filter for the new one i need to create but the 2 views don't work together, only if i disable one of them, does it work. side note: i have removed user preferences for views in testing, and that didn't help either. 

Script:

(function overrideView(view, is_list) {
        // Add your code here
	if(global.hasThisRole("first_role")){ 
	answer = "first_change_form";  // set the new view to answer
	}
        else if(global.hasThisRole("second_role") //need to query for short description or change type as well for second_role and apply second change form view
        answer = "second_change_form";
	else{
	answer = "third_role"; //and if none matched, default to this view
	}
})(view, is_list);

I know i cant access current in the view script as it runs server side, but how can i format the code so that i can query if the change record has a specific short description or change type ?

 

Any scripting help would be greatly appreciated. Thank you. 

 

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

You can use condition in view rule to specify paticular change type or short description.

 

find_real_file.png

 

IF you want to access in view rule script, then use below code 

var url = gs.action.getGlideURI().getMap();


var sysId = url.get('sys_id');




var gr = new GlideRecord('change_request');


if (gs.getUser().getRecord().getValue('u_type') == '10') {




answer = 'portal';



}else{



if (gr.get(sysId)) {



if (gr.type == '0') {



answer = '';


}else if(gr.type == '1'){



answer = 'emergencyChange';



}


}


}










 

Regards,

Sachin

View solution in original post

1 REPLY 1

sachin_namjoshi
Kilo Patron
Kilo Patron

You can use condition in view rule to specify paticular change type or short description.

 

find_real_file.png

 

IF you want to access in view rule script, then use below code 

var url = gs.action.getGlideURI().getMap();


var sysId = url.get('sys_id');




var gr = new GlideRecord('change_request');


if (gs.getUser().getRecord().getValue('u_type') == '10') {




answer = 'portal';



}else{



if (gr.get(sysId)) {



if (gr.type == '0') {



answer = '';


}else if(gr.type == '1'){



answer = 'emergencyChange';



}


}


}










 

Regards,

Sachin