Customise Security in CRM Portal/ADX Studio using Liquid Template

In CRM Portal we can control the records using entity permission based on privileges but it will be specific to Web Role not specific to the particular Logged in user in Portal.

This blog post demonstrates how to control the record based on the specific portal logged-in user.

Let’s take the following scenario, Primary contact in Account Entity can only edit the record details in CRM Portal. In Order to achieve this, please follow the below solution steps.

Step 1: Create a New Web Template as ‘Edit Account Details Web Template and add the Liquid Template code.

Liquid Template Code:

{% extends 'Layout 1 Column' %}

{% block main %}

{% include 'Page Copy' %}

{% include 'Child Navigation' showdescriptions: true %}

{% if page.adx_entitylist %}

{% include 'entity_list' key: page.adx_entitylist.id %}

{% endif %}

<!-- Check Security URL -->

{% assign user_id = user.id | downcase %}

{% assign account = entities.account[request.params['id']] %}

{% if account %}

{% assign primarycontact = <strong>{{</strong>account.primarycontactid.id<strong>}}</strong> %}

{% if user_id == primarycontact %}

<!-- Check Security URL -->

{% if page.adx_entityform %}

{% entityform id: page.adx_entityform.id %}

{% endif %}

{% if page.adx_webform %}

{% webform id: page.adx_webform.id %}

{% endif %}

{% else %}

//redirect to Access Denied

window.location.href = "/access-denied";

{% endif %}

{% else %}

//redirect to Access Denied

window.location.href = "/access-denied";

{% endif %}

<!-- End Section -->

{% endblock %}

Step 2: Create a New Page Template as ‘Edit Account Details Page Template and select the ‘Edit Account Details Web Template

Step 3: Create a new Entity Form for Edit the Account Details, please check the below for more details

Step 4: Create a new Web Page and Select ‘Edit Account Details Page Template’ and Entity Form as ‘Edit Account Details

In CRM, Select Account and Primary Contact should be Portal Logged-in user and try to edit in the Portal. Below Example, it will allow only ‘Sathis K’ Portal user to Edit Account.

In Portal, Login with ‘Sathis K’ and Select the Edit group details in Partial URL. For example:

https://sample.microsoftcrmportals.com/edit-account-details/?id=DCC81791-A615-E711-8104-C4346BC540C4

Now in Portal, try to Login with another user and try to edit the account details(https://sample.microsoftcrmportals.com/edit-account-details/?id=DCC81791-A615-E711-8104-C4346BC540C4)  it will redirect to Access Denied Page because only Primary Contact is only allowed to edit the details.

Design a site like this with WordPress.com
Get started