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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Krishna,



I think it's only based on some condition or role and we could not determine using the form field values


Because when i tried printing the form field value using current.field_name it gave error.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Hi Ankur,


We can do it on condition based without scripting from the same tab,


If I don't click advanced, It gives me a option to choose based on a field value. However, in this case, I'm not seeing the option of selecting View based on User Role.


find_real_file.png


I need both conditions to be in place for my view.


I'm trying to figure it the code in script to access field values.



Regards,


Krishna


Alikutty A
Tera Sage

Hi,



current is not in the scope of script field and you can do both the validation at a single place. You can either use it as a condition for checking on fields or use script for checking roles etc. The script runs on server side so you can also use Glide queries in it.





Thanks


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


Typo.



You can't do both the validation at a single place.




Thanks


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