View Rule based on field value

tkrishna29
Giga Guru

Hi,

I'm able to show a User view based on the User role.

find_real_file.png

How can I add further condition of showing the view based on user role and current field value for that record user opened. (Lets say if status = 'NEW' / 'IN PROGRESS', I want to show a different view for the same user)

Also, What Is the best practice to use views / UI policies?   if I meant to display different views at different stages in my workflow to same / different users.

Thanks,

Krishna

1 ACCEPTED SOLUTION

Hi,



Please try this out, let me know if it worked.



function onLoad() {


  var view =getView().toString();   // Get the current view



  if(view == 'itil' || view == 'ess'){


          return false;     // Dont switch for itil or ess


  }else if (// Add your conditions){


            switchView('section','incident','my_view');


  }


}






Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

10 REPLIES 10

Hi,


If I want to try GlideQuery, I still have to get the current record sysid to query from DB.



When you say we can't do both validations at same place, Do you mean that is the system's limitation? That does not sound logical.



Thanks.


Yes unfortunately this seems to be a limitation.



The topic was previously discussed in Re: Current object not available in View Rule Script and Nick had checked with HI but they advised that it is not possible. For your scenario you can try to achieve the functionality by an on load client script and using switchView(type, table, view);



The 'type' parameter is either 'list' (to redirect to a list view) or 'section' (to change to a form view).


The 'table' should be your current table


The 'view' should be the view to redirect



On incident form, you can add this in an onLoad client script



function onLoad() {


                if(g_user.hasRole('itil') && g_form.getValue('state') == 'new'){


                      switchView('section','incident','itil');


                }


}



Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


Thank you Alikutty.


I tried this one in the morning. However, I see that this is going on infinite loop when I load the form. It's loading again and again.


I believe once it loads the new view, it runs the onLoad() event again and it goes infinite.


Is there a way I can put the condition on this so that if the current view is itil, DO NOT load.


Like - If current view != 'itil' then switchview.



I'm still in learning mode to understand more about the script objects. Very much appreciate your help.



Thanks,


Krishna


Hi,



Please try this out, let me know if it worked.



function onLoad() {


  var view =getView().toString();   // Get the current view



  if(view == 'itil' || view == 'ess'){


          return false;     // Dont switch for itil or ess


  }else if (// Add your conditions){


            switchView('section','incident','my_view');


  }


}






Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


That worked great. Thanks a lot Alikutty.