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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

sales order unlock price update from Plugin

(0) ShareShare
ReportReport
Posted on by 3,255
Hi All
When a sales order is created from a quote , on the salesorder entity ispricelocked field set to true preventing updating lines. Can we create a plugin that trigger on salesorderdetail update message that unlocks header ispricelocked (false) on preoperation? or is there other solution than user manually setting header field on button. the problem is qty update doesnt calculate total and price as entity locked. Use CalculatePrice message and disabled system pricing
I have the same question (0)
  • Verified answer
    Muhammad Shahzad Shafique Profile Picture
    2,373 Most Valuable Professional on at
    Plugin on “SalesOrderDetail” Update (Pre-Operation) 
    Yes, you can create a plugin registered on the “Update” message of “SalesOrderDetail” (Pre-Operation stage) that: 
    1. Checks if “IsPriceLocked = true” on the parent “SalesOrder”. 
    2. Sets “IsPriceLocked = false” on the header if needed. 
    3. Recalculates pricing (if required) using “CalculatePrice” after unlocking. 
    public void Execute(IServiceProvider serviceProvider)
    {
        var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
        var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
        var service = serviceFactory.CreateOrganizationService(context.UserId);
    
        if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity target)
        {
            var salesOrderDetail = service.Retrieve("salesorderdetail", target.Id, new ColumnSet("salesorderid"));
            var salesOrderId = salesOrderDetail.GetAttributeValue<EntityReference>("salesorderid");
    
            // Get the Sales Order header
            var salesOrder = service.Retrieve("salesorder", salesOrderId.Id, new ColumnSet("ispricelocked"));
            bool isPriceLocked = salesOrder.GetAttributeValue<bool>("ispricelocked");
    
            if (isPriceLocked)
            {
                // Unlock the Sales Order
                Entity updateOrder = new Entity("salesorder", salesOrderId.Id);
                updateOrder["ispricelocked"] = false;
                service.Update(updateOrder);
    
                // Optionally trigger CalculatePrice if needed
                // var request = new CalculatePriceRequest() { Target = new EntityReference("salesorder", salesOrderId.Id) };
                // service.Execute(request);
            }
        }
    }




     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 72 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 29 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans