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 ("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 ("dds_opportunity_name") == opportunity.ToEntityReference()).ToList (); //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 (); 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 ("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 ("ownerid"); orgContext.UpdateObject(retFields); } else { retFields["dds_split_deal_opl"] = SplitdealOption; retFields["dds_split_percent_opl"] = opportunity.GetAttributeValue ("dds_split_percentage_on_opportunity"); retFields["dds_split_with_opl"] = opportunity.GetAttributeValue ("dds_split_with"); orgContext.Attach(retFields); orgContext.UpdateObject(retFields); } } orgContext.SaveChanges(); } }
↧
Forum Post: RE: Plugin User with ID does not have Update permissions for the attribute in the entity
↧