Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

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

Posted on by Microsoft Employee

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
    meelamri 13,204 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
    Community Member Microsoft Employee 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
    meelamri 13,204 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
    Community Member Microsoft Employee 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
    meelamri 13,204 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
    Community Member Microsoft Employee 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
    meelamri 13,204 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans