Jump to content
  • 0

How to show/ hide values based on user role?


Aleksandra

Question

Hello,

I hope someone can help me with this one. I have built a data page for adding activities and would like to show values in my field Lead ID (which is a dropdown) based on the user's role. If the user is Admin, then they should be able to view all leads with the status New and if the user is Employee, they should be able to view only leads with the status Assigned (and show leads assigned to them only).

 

I know the easiest way would be to build two forms - one for admins and the other for employees but I have a limited number of data pages available. Is there any way to work around this?

 

Many thanks,

Aleksandra

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Hello @Aleksandra,

Basically, this option is helpful https://howto.caspio.com/authentications-and-connections/authentication/record-level-security/filter-lookup-dropdown-or-listbox-based-on-user-or-role/

But this does not work for this case, because the Admin should see all the records.

You can test the following:
1) Create a Virtual field (for example, Virtual 1), set it as a Dropdown, and use a corresponding table as a lookup. This will be used by an Admin.

2) Create another Virtual field (for example, Virtual 2),  set it as a Dropdown, and apply a Security option for it as described in the article I shared. This will be used by an Employee.

3) Create Rules to hide the Virtual fields.
The Rule condition should be based on the auth parameter. The syntax is [@authfield:Field_Name]
If the Role = Admin, the Virtual 2 is hidden, if the Role = Employee, the Virtual 1 is hidden.

For example:
w0jgOlv.png 

4) The Activity field should be a Calculated value to get the selected Activity:

LSmaXb1.png

The logic is the following: if the Virtual 1 field is not blank, use the value selected in Virtual 1, if the Virtual 2 field is not blank, use the value selected in Virtual 2

CASE 
WHEN '[@cbParamVirtual1]' != ''
THEN '[@cbParamVirtual1]'
WHEN '[@cbParamVirtual2]' != ''
THEN '[@cbParamVirtual2]'
END

Please note that Dropdowns should have some neutral word like 'select' (without value), so they are blank by default. 

xw4pHkh.png

Hope this works. 

Link to comment
Share on other sites

  • 0

Hi @CoopperBackpack, thank you for your response. I've already tried something similar with Virtual fields and it didn't work, but I'll try your approach. My concern is that if I create virtual fields, the values I add through them won't be saved in the table, am I right? What I need to do is to save the value Lead_ID which I would select through the virtual field the way I explained (all new leads available for admin and assigned leads available for employees). 

This is the relationship between the Leads and Activities table: 

image.png.b8eb494c4fcd6467b931241267424b31.png

Also, here is what my form for adding activities currently looks like (it enables employees only to add their activity). Activity shouldn't be a calculated field as they should be free to select among 2 options: call or email and their notes. The only concern is the dropdown options for the company (which is actually Lead_ID):

image.thumb.png.96eb312f7808617b1e2fa90fd24e87f0.png

I hope this explanation is clear enough.

Best,

Aleksandra

Link to comment
Share on other sites

  • 0

I created a solution (or at least, I am almost there). Here is what I did:

1. I created Virtaual 1 as a dropdown value where I set up values that should be visible for Admin.

2. I created a Virtual 2 as a dropdown value where I set up values that should be visible for Employee.

3. I created a conditional rule to hide Virtual 1 when role is not equal Admin and to hide Virtual 2 when role is not equal to Employee.

4. I converted Lead_ID to a calculated value and inserted the following formula: CASE 
WHEN '[@cbParamVirtual1]' !=' '
THEN '[@cbParamVirtual1]'
WHEN '[@cbParamVirtual2]' !=' '
THEN '[@cbParamVirtual2]'
END.

I tested this and it worked. The only thing that would make the form look better is hiding the Lead ID field from the form, but when I try to do that, I cannot submit a record so I am not sure how to approach it. But, the most important thing is that this solution works. Thank you so much @CoopperBackpack for your help.

 

Best regards,

Aleksandra

Link to comment
Share on other sites

  • 0

Hello @Aleksandra,

To answer your question about saving the value to the table. For that, the Calculated Value is used on the table field. Virtual fields are just auxiliary fields.  
Please note that whenever the field From Element = Calculated Value, it is possible to hide it by the standard options. It is the 'Hide field' checkbox on the Advanced tab. 

Wt2Q8V1.png

Link to comment
Share on other sites

  • 0

I am trying to do something similar with a tabular report that shows users' activities.  I don't have an option to insert virtual fields here, so I inserted an HTML block. Admin should be able to see all records, while Employees should be able to see their records only. I inserted the following script to try to show only values that belong the employees:

<div id="row-marker-[@field:Activity_ID]"></div>

<script>
    var marker = document.getElementById('row-marker-[@field:Activity_ID]');
    var column = marker.parentNode;

    if ('[@field:Employee_Role]' === 'Admin') && ('[@field:Employee_Email]' !== '[@authfield:CRMStarter_Employees_Email]')
    {
        var row = column.parentNode;
        row.style.display = 'none';
    }
</script>

When I entered this second condition  ('[@field:Employee_Email]' !== '[@authfield:CRMStarter_Employees_Email]'), the report didn't return the correct result. Any ideas on how to approach this and where I am making a mistake? I tried to scroll through existing solutions on the community forum, but they weren't helpful.

Many thanks,

Aleksandra

 

Edit: I managed to solve this and here is the code I inserted in the HTML block: 

<div id="row-marker-[@field:Activity_ID]"></div>

<script>
    var marker = document.getElementById('row-marker-[@field:Activity_ID]');
    var column = marker.parentNode;

    if ('[@field:Employee_Email]' !== '[@authfield:CRMStarter_Employees_Email]' && '[@authfield:CRMStarter_Employees_Role]' !== 'Admin')
    {
        var row = column.parentNode;
        row.style.display = 'none';
    }
</script>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...