{Dynamics Portal :: Steps to perform operations based on the Portal user role on the form}

This is most common requirement that we need to show hide some fields based on the certain fields or user roles. It’s quite easy in Dynamics 365/CRM forms. We can utilize the Business Rules. But business rules will not work on the Dynamics portal form.

How to achieve this functionality in the Dynamics portal?

We can utilize the odata options to retrieve the records and find out the roles of the logged in user.

If we are using the Liquid templates/ Web templates to display the form in portals, we can do easily by utilizing the portal syntax.

{% assign is_admin = user | has_role: 'Administrator' %}

Above syntax helps to set the logged-in user is Administrator or not in the is_admin variable. It will hold Boolean value. 

If we are using the web templates, we can directly utilize this variable in the template. 

If we are using Entity Forms, we will not have access to the web template syntax in Entity form based java-script. But we planned to have one html input element in the web template and store the above results and kept it hidden.

<input id="isadmin" style="display:none" type="text" value="{{is_admin}}">

On load of the page, the value will be manipulated and we can access that value using java-script. 

if($('#isadmin').val() == "true") {
//do something for admin user
}else
{
//do something for non-admin user
}

we can utilize the web template syntax and form java-script to play around on this.Similar logic can be applied for different scenarios.

Hope it makes sense. Please do let me know if you need any help on this. Happy to assist..

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: