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

How to set "Display Value" condition of the reference field of the target table in "View Rule" script?

Aki17
Kilo Guru

I created a View Rule to automatically change Views between Portal and internal platform, with the condition like below:

If
- u_application_id is "1"
AND
- Accessed from Service Portal
Then
Apply "u_1_portal" View


Else if
- u_application_id is "1"
AND
- Accessed from internal platform (NOT portal)
Then
Apply "u_1" View

 

"u_application_id" is the reference field, so I set "sys_id" in the IF condition, but I would like to use "display value" which it's easier to specify the condition value.

Could someone please modify the following script to set condition based on display value of "u_application_id" field instead of sys_id?

(function overrideView(view, is_list) {
 //get URL details
 var url = gs.action.getGlideURI().getMap();

 //Determine if in portal view
 var isPortal = url.get('id');
        var sys_id = url.get('sys_id');
        if(sys_id){
 var gr = new GlideRecord('u_shinsei');
        if(gr.get(sys_id)){ 
   if(gr.u_application_id == 'sys_id' && isPortal){
    answer = 'u_1_portal';
   }
   if(gr.u_application_id == 'sys_id' && !isPortal ){
    answer = 'u_1';
   }
  }
  }else{
   answer=null;
  }
})(view, is_list);

Best Regards,

Aki

1 ACCEPTED SOLUTION

Sai Kumar B
Mega Sage

@Aki 

Could you try the below with the getDisplayValue() method?

(function overrideView(view, is_list) {
 //get URL details
 var url = gs.action.getGlideURI().getMap();

 //Determine if in portal view
 var isPortal = url.get('id');
        var sys_id = url.get('sys_id');
        if(sys_id){
 var gr = new GlideRecord('u_shinsei');
        if(gr.get(sys_id)){ 
   if(gr.getDisplayValue('u_application_id') == 'Give display value' && isPortal){
    answer = 'u_1_portal';
   }
   if(gr.getDisplayValue('u_application_id') == 'Give display value' && !isPortal ){
    answer = 'u_1';
   }
  }
  }else{
   answer=null;
  }
})(view, is_list);

View solution in original post

1 REPLY 1

Sai Kumar B
Mega Sage

@Aki 

Could you try the below with the getDisplayValue() method?

(function overrideView(view, is_list) {
 //get URL details
 var url = gs.action.getGlideURI().getMap();

 //Determine if in portal view
 var isPortal = url.get('id');
        var sys_id = url.get('sys_id');
        if(sys_id){
 var gr = new GlideRecord('u_shinsei');
        if(gr.get(sys_id)){ 
   if(gr.getDisplayValue('u_application_id') == 'Give display value' && isPortal){
    answer = 'u_1_portal';
   }
   if(gr.getDisplayValue('u_application_id') == 'Give display value' && !isPortal ){
    answer = 'u_1';
   }
  }
  }else{
   answer=null;
  }
})(view, is_list);