web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin User with ID does not have Update permissions for the attribute in the entity

(0) ShareShare
ReportReport
Posted on by 227

Hello All,

I am having trouble with a plugin I am working on.  It is a synchronous update plugin from the Opportunity entity that when a condition is met will circle through the children entities (called dds_opportunity_product_line or OPLs in this example) and update those related to this opportunity.  When I make the triggering update on the Opportunity I get this error:

An error occured while processing this request.
User with ID a01c391b-d837-e411-8744-6c3be5a8de30 does not have Update permissions for the dds_manager_sales_price_discount_limit attribute in the dds_opportunity_product_line entity. The dds_opportunity_product_lineid of the record is

This field is setup for field security and this user does not have access, I understand that from the error, but this field is not changing with the plugin, my plugin code below.  The trigger is when the field on Opportunity 'dds_split_deal_opportunity' is changed.  When I step through the code it looks as if my plugin is trying to update the entire child record instead of just the three fields I am changing.

Thank you

public static void UpdateOPLsOnchangeofOpty(Entity opportunity, IOrganizationService orgService)
{
var SplitdealOption = opportunity.GetAttributeValue<OptionSetValue>("dds_split_deal_opportunity");
using (OrganizationServiceContext orgContext = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(orgService))
{
var OProductLineItems = orgContext.CreateQuery("dds_opportunity_product_line").Where(p =>
p.GetAttributeValue<EntityReference>("dds_opportunity_name") == opportunity.ToEntityReference()).ToList<Entity>();

foreach (var OPLs in OProductLineItems)
{
if (opportunity.GetAttributeValue<OptionSetValue>("dds_split_deal_opportunity").Value == 1)
{
OPLs["dds_split_deal_opl"] = SplitdealOption;
OPLs["dds_split_percent_opl"] = 0.00;
OPLs["dds_split_with_opl"] = opportunity.GetAttributeValue<EntityReference>("ownerid");
orgContext.UpdateObject(OPLs);
}
else
{
OPLs["dds_split_deal_opl"] = SplitdealOption;
OPLs["dds_split_percent_opl"] = opportunity.GetAttributeValue<decimal>("dds_split_percentage_on_opportunity");
OPLs["dds_split_with_opl"] = opportunity.GetAttributeValue<EntityReference>("dds_split_with");
orgContext.UpdateObject(OPLs);
}
}
orgContext.SaveChanges();
}
}

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi Mike,

    Try this:

    While retrieving OProductLineItems list, select only columns which you need to update, then within the foreach loop set the values and execute update.

    Thanks,

    Indika.

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    Instead of updating current object create an new object of your entity and just these three fields and entity id, and update it.

  • st738407 Profile Picture
    227 on at

    Thank you for your help, I tried to add Select into my plugin, but kept getting failures.  I eventually ended up with it looking like the below, but now I am told

    The context is already tracking a different 'dds_opportunity_product_line' entity with the same identity

    public static void UpdateOPLsOnchangeofOpty(Entity opportunity, IOrganizationService orgService)

           {

               var SplitdealOption = opportunity.GetAttributeValue<OptionSetValue>("dds_split_deal_opportunity");

               using (OrganizationServiceContext orgContext = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(orgService))

               {

                  var OProductLineItems = orgContext.CreateQuery("dds_opportunity_product_line").Where(p =>

                       p.GetAttributeValue<EntityReference>("dds_opportunity_name") == opportunity.ToEntityReference()).ToList<Entity>();

                  //var OPLIneed = (from dds_opportunity_product_line in orgContext.CreateQuery("dds_opportunity_product_line")

                    //             where dds_opportunity_product_line["dds_opportunity_name"] == opportunity.ToEntityReference()

                      //           select dds_opportunity_product_line).ToList<Entity>();

                   foreach (var OPLs in OProductLineItems)

                  //foreach (var OPLs in OPLIneed)

                   {

                       var retFields = orgService.Retrieve("dds_opportunity_product_line", OPLs.Id, new ColumnSet("dds_split_deal_opl", "dds_split_percent_opl", "dds_split_with_opl", "dds_opportunity_product_lineid" ));

                       if (opportunity.GetAttributeValue<OptionSetValue>("dds_split_deal_opportunity").Value == 1)

                       {

                           retFields["dds_split_deal_opl"] = SplitdealOption;

                           retFields["dds_split_percent_opl"] = 0.00;

                           retFields["dds_split_with_opl"] = opportunity.GetAttributeValue<EntityReference>("ownerid");

                           orgContext.UpdateObject(retFields);

                       }

                       else

                       {

                           retFields["dds_split_deal_opl"] = SplitdealOption;

                           retFields["dds_split_percent_opl"] = opportunity.GetAttributeValue<decimal>("dds_split_percentage_on_opportunity");

                           retFields["dds_split_with_opl"] = opportunity.GetAttributeValue<EntityReference>("dds_split_with");

                           orgContext.Attach(retFields);

                           orgContext.UpdateObject(retFields);

                       }

                   }

                   orgContext.SaveChanges();

               }

           }

  • Verified answer
    Daniel Wikell Profile Picture
    2,360 on at

    In cases like these, I usually just avoid the context altogether and go with the orgservice.This way you have complete control over which fields are updating without the hassle of brawling with the context tracking.

    In your case this means creating a new Entity object, assigning the fields you want changed and then using the orgService.Update method:

    //This code example updates the dds_split_deal_opl field only. All other fields unchanged.

    var updOPL = new Entity();

    updOPL.Id = retFields.Id;

    updOPL.Attributes.Add("dds_split_deal_opl", SplitdealOption);

    orgService.Update(updOPL);

    edit: changed the attribute assignment line. Not used to late-bound coding anymore so not sure if previous one worked..

  • st738407 Profile Picture
    227 on at

    Thank you, this worked.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Varsha deshpande Profile Picture

Varsha deshpande 5

#2
JS-09031509-0 Profile Picture

JS-09031509-0 3

#3
Ciprian  P Profile Picture

Ciprian P 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans