Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Plugin restriction to edit majority of fields on the form allowing only few for a security role

(1) ShareShare
ReportReport
Posted on by

When a user with specific security role try to modify values on the form apart from couple of fields which are to be excluded, CRM should not allow it. I am using pre-operation update plugin for this. I am getting the security role in the plugin as expected. However, I am facing issue writing the condition for certain fields(7) to updated fine but if any other fields for the context are updated throw alert.
The reason I am using plugin is to be able to apply same restrictions when required user try to modify data for the entity via bulk edit or import.

Please suggest.

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: Plugin restriction to edit majority of fields on the form allowing only few for a security role

    Maybe I'm wrong about the implementation. But the general idea is explained in my code which could work after your debugging

    A synchronous workflow can also be the cause of the problem. Debugging can help us to implement the right code.

    Please add some tracing and check what attribute throw the exception.

  • Community Member Profile Picture
    on at
    RE: Plugin restriction to edit majority of fields on the form allowing only few for a security role

    Yes Mehdi, tried with pre-validation as well. Did not throw exception as expected

  • meelamri Profile Picture
    13,216 User Group Leader on at
    RE: Plugin restriction to edit majority of fields on the form allowing only few for a security role

    Hi Sharma,

    Did you register the plugin in pre-validation? Try to debug using ITracingService.

  • Community Member Profile Picture
    on at
    RE: Plugin restriction to edit majority of fields on the form allowing only few for a security role

    Hi Mehdi,

    Thanks for your support.

    Tried with your code snippet, however, it is showing alert on these seven fields and the filtered attributes which are checked as part of pre operation and allowing all other fields to be updated.

    As the task is reaching deadline, we are currently only applying form restrictions using JS.

    Thanks for your time

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: Plugin restriction to edit majority of fields on the form allowing only few for a security role

    Hi, 

    Please refer to my sample code and comments: 

    Entity target = executionContext.InputParameters["Target"] as Entity;
                
    List allowedFields = new List();
    //Allow 7 fields
    allowedFields.Add("name");
    allowedFields.Add("telephone1");
    allowedFields.Add("tickersymbol");
    allowedFields.Add("customertypecode");
    allowedFields.Add("industrycode");
    allowedFields.Add("ownershipcode");
    allowedFields.Add("preferredcontactmethodcode");
                
    //The primary key is always included in the target.
    //It must also be added.
    allowedFields.Add("accountid");
    
    foreach (var att in target.Attributes){
        if (!allowedFields.Contains(att.Key))
            throw new InvalidPluginExecutionException("error");
    }

  • Community Member Profile Picture
    on at
    RE: Plugin restriction to edit majority of fields on the form allowing only few for a security role

    Thanks for your quick response Mehdi.

    Apart from those 7 fields, all other fields I need to restrict(number would be in hundreds). So, can you suggest a condition to allow editing of those 7 fields but any other fields non editable for that entity.

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at
    RE: Plugin restriction to edit majority of fields on the form allowing only few for a security role

    Hi,

    You can check if the target contains the fields you want to restrict.

    Entity target = executionContext.InputParameters["Target"] as Entity;

    if (target.Contains("fieldExample")){

    throw new InvalidPluginExecutionException("your error message");

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Product updates

Dynamics 365 release plans