How to change view based on role of user?

Community Alums
Not applicable

Suppose there are two roles, roleA and roleB. There are few users present in each of the role.

When user of roleA visits incident form, he should be able to see viewA and similarly when user of roleB visits incident form, he should be able to see viewB.

Please help me to know, how can I achieve above scenario?

 

7 REPLIES 7

palmen
Tera Guru

You can do this with a View Rule.

It's possible to script it, so look at any of the out of box view rules containing a script and you can probably figure out how to do this.

Example from other view rule, modify to your needs.

(function overrideView(view, is_list) {
	
	// Add your code here
	answer = view;
	if (view == "")
		answer = 'Automated';  // set the new view to answer

})(view, is_list);

Community Alums
Not applicable

Hi palmen,

I have tried with below View Rule but it is not working, can you help me with it?

Make sure you have proper view names in the code, same as for roles.
Not sure if you have to declare a variable for anser, otherwise code looks good to me, add some log statements into the rule, one in beginning to make sure the rule itself is executed and then a log statement within each if statement to see if it takes that part or somewhere else.

You could try with a very simple rule like this, just to make sure you got the syntax correct.

(function overrideView(view, is_list) {
	
   answer = 'your_view_name';

})(view, is_list);

If this code works for you to show your_view_name, then add the condition to it.

Priyanka136
Mega Guru

Hi sindhu21,

You created one view with name "ViewA" this view should be visible for RoleA users only, and similarly for ViewB also.

So you have to write View Rule script. Try this code.

if (!gs.hasRole('RoleB')) 
{
         if (gs.hasRole('RoleA')) 
         {

            answer = "ViewA";

         }

}

Let me know, if you have any questions.

I hope it work, please mark it Correct or Helpful based on Impact....!!!!

Warm Regards,

Priyanka

find_real_file.png

www.dxsherpa.com