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)

Plugins won't work when quote is created with different Price List

(0) ShareShare
ReportReport
Posted on by

Hello guys, 

I have couple of plugins on the "quote" entity and they work just fine when the Price list is USD. When I create a new Quote, and set the Price List to something other than "USD", like "EUR" per say - I'm not allowed to create a quote product for this quote, and the error that I get is "ISV Code aborted the operation".


I know that this error is given when you have more than one plugin updating the same entity, but I don't use the pricelist for none of this plugins, except for one, that is not even triggered on create of quote, but on change of a yes/no field. 

Here is the code that is in that plugin:

 protected void ExecuteQuoteCreateOrders(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            // TODO: Implement your custom Plug-in business logic.

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService service = localContext.OrganizationService;
            Guid quoteProductID = (Guid)((Entity)context.InputParameters["Target"]).Id;
            var serviceContext = new OrganizationServiceContext(service);
            ColumnSet set = new ColumnSet();
            set.AllColumns = true;
            var quote = service.Retrieve("quote", quoteProductID, set);

            if (context.Depth > 1)
            {
                return;
            }
            else
            {

                var customerID = (EntityReference)quote["customerid"];

                var customer = service.Retrieve(customerID.LogicalName, customerID.Id,
                    new ColumnSet() { AllColumns = true });

                if (quote.Contains("new_createinvoice"))
                {
                    var salesorderType = (OptionSetValue)quote["new_createinvoice"];

                    if (salesorderType.Value == 1)
                    {

                        string quoteName = (string)quote["name"];
                        string orderProductName = "Advance payment for " + quoteName;
                        var prepayedAmount = (Money)quote["new_prepayedamount"];
                        var advanceProductId = "14";
                        var salesorder = new Entity("salesorder");
                        salesorder["name"] = quoteName + " Invoice Order for the Prepayment";
                        salesorder["quoteid"] = new EntityReference(quote.LogicalName, quote.Id);
                        salesorder["customerid"] = new EntityReference(customer.LogicalName, customer.Id);
                        salesorder["pricelevelid"] = (EntityReference)quote["pricelevelid"];
                        salesorder["new_recommendedtotal"] = (Money)quote["new_prepayedamount"];
                        salesorder["new_pricingtype"] = new OptionSetValue(((OptionSetValue)quote["new_pricingtype"]).Value);
                        salesorder["new_reloadflag"] = false;

                        var orderID = (Guid)service.Create(salesorder);


                        //Create the order detail
                        var orderProduct = new Entity("salesorderdetail");

                        orderProduct["salesorderid"] = new EntityReference("salesorder", orderID);

                        //////retrieve product

                        ConditionExpression condition = new ConditionExpression();
                        condition.AttributeName = "name";
                        condition.Operator = ConditionOperator.Equal;
                        condition.Values.Add("pc");

                        FilterExpression filter = new FilterExpression();
                        filter.AddCondition(condition);

                        QueryExpression query = new QueryExpression();
                        query.EntityName = "uom";
                        query.ColumnSet = new ColumnSet(true);
                        query.Criteria = filter;


                        // Query for the UOM

                        ConditionExpression conditionProduct = new ConditionExpression();
                        conditionProduct.AttributeName = "productnumber";
                        conditionProduct.Operator = ConditionOperator.Equal;
                        conditionProduct.Values.Add(advanceProductId);

                        FilterExpression filterProduct = new FilterExpression();
                        filterProduct.AddCondition(conditionProduct);

                        QueryExpression queryProduct = new QueryExpression();
                        queryProduct.EntityName = "product";
                        queryProduct.ColumnSet = new ColumnSet(true);
                        queryProduct.Criteria = filterProduct;


                        EntityCollection uomCollection = service.RetrieveMultiple(query);
                        EntityCollection productCollection = service.RetrieveMultiple(queryProduct);
                        //uom.Entities.F

                        var firstUom = uomCollection.Entities.FirstOrDefault();
                        var firstProduct = productCollection.Entities.FirstOrDefault();
                        //foreach (var product in uom.Entities)
                        //{
                        //    orderProduct["productid"] = product.ToEntityReference();
                        //}


                        //EntityCollection uoms = service.RetrieveMultiple(unitQuery);
                        //var uomProduct = uoms.Entities[0];
                        //var uom = service.Retrieve("uom", new Guid("06EBB338-468D-437B-B547-A3E600EB9A97"), new ColumnSet(){AllColumns=true});
                        var uom = service.Retrieve(firstUom.LogicalName, firstUom.Id, new ColumnSet() { AllColumns = true });
                        //throw new InvalidPluginExecutionException(firstProduct.Id.ToString());

                        //var product = service.Retrieve("product", new Guid("0DD28827-C9D5-E311-9397-00155D0A4E33"), new ColumnSet(){AllColumns=true});
                        var product = service.Retrieve(firstProduct.LogicalName, firstProduct.Id, new ColumnSet() { AllColumns = true });
                        orderProduct["productid"] = new EntityReference("product", product.Id);
                        orderProduct["uomid"] = new EntityReference("uom", uom.Id);
                        orderProduct["description"] = (string)orderProductName;
                        orderProduct["tax"] = (decimal)0;
                        orderProduct["new_pricingtype"] = new OptionSetValue(((OptionSetValue)quote["new_pricingtype"]).Value);
                        orderProduct["priceperunit"] = new Money(prepayedAmount.Value);
                        //throw new InvalidPluginExecutionException(prepayedAmount.Value.ToString());
                        orderProduct["quantity"] = (decimal)1;
                        orderProduct["new_pricingtype"] = new OptionSetValue(1);
                        orderProduct["new_ratio"] = (decimal)1;
                        orderProduct["manualdiscountamount"] = new Money(0);
                        orderProduct["new_specificdiscountpercentage"] = (decimal)0;
                        orderProduct["new_grossannualincome"] = new Money(prepayedAmount.Value);
                        orderProduct["new_gaixratio"] = new Money(prepayedAmount.Value);
                        orderProduct["new_recommendedvalue"] = new Money(prepayedAmount.Value);
                        orderProduct["new_fixedpriceplusratio"] = new Money(prepayedAmount.Value);


                        service.Create(orderProduct);
                        //service.Update(salesorder);


                    }
                    else if (salesorderType.Value == 2)
                    {

                        string quoteName = (string)quote["name"];
                        string orderProductName = "Advance payment for " + quoteName;
                        var prepayedAmount = (Money)quote["new_prepayedamount"];

                        var salesorder = new Entity("salesorder");
                        salesorder["name"] = quote["name"] + " Invoice Order for the Residual";
                        salesorder["quoteid"] = new EntityReference(quote.LogicalName, quote.Id);
                        salesorder["customerid"] = new EntityReference(customer.LogicalName, customer.Id);
                        salesorder["pricelevelid"] = (EntityReference)quote["pricelevelid"];
                        salesorder["new_recommendedtotal"] = (Money)quote["new_prepayedamount"];
                        salesorder["new_pricingtype"] = new OptionSetValue(((OptionSetValue)quote["new_pricingtype"]).Value);
                        salesorder["new_reloadflag"] = false;

                        var orderID = (Guid)service.Create(salesorder);


                        //Create the order detail
                        var orderProduct = new Entity("salesorderdetail");

                        orderProduct["salesorderid"] = new EntityReference("salesorder", orderID);

                        //////retrieve product

                        ConditionExpression condition = new ConditionExpression();
                        condition.AttributeName = "name";
                        condition.Operator = ConditionOperator.Equal;
                        condition.Values.Add("pc");

                        FilterExpression filter = new FilterExpression();
                        filter.AddCondition(condition);

                        QueryExpression query = new QueryExpression();
                        query.EntityName = "uom";
                        query.ColumnSet = new ColumnSet(true);
                        query.Criteria = filter;


                        // Query for the UOM

                        ConditionExpression conditionProduct = new ConditionExpression();
                        conditionProduct.AttributeName = "productnumber";
                        conditionProduct.Operator = ConditionOperator.Equal;
                        conditionProduct.Values.Add("14");

                        FilterExpression filterProduct = new FilterExpression();
                        filterProduct.AddCondition(conditionProduct);

                        QueryExpression queryProduct = new QueryExpression();
                        queryProduct.EntityName = "product";
                        queryProduct.ColumnSet = new ColumnSet(true);
                        queryProduct.Criteria = filterProduct;


                        EntityCollection uomCollection = service.RetrieveMultiple(query);
                        EntityCollection productCollection = service.RetrieveMultiple(queryProduct);
                        //uom.Entities.F

                        var firstUom = uomCollection.Entities.FirstOrDefault();
                        var firstProduct = productCollection.Entities.FirstOrDefault();

                        var uom = service.Retrieve(firstUom.LogicalName, firstUom.Id, new ColumnSet() { AllColumns = true });

                        var product = service.Retrieve(firstProduct.LogicalName, firstProduct.Id, new ColumnSet() { AllColumns = true });
                        orderProduct["productid"] = new EntityReference("product", product.Id);
                        orderProduct["uomid"] = new EntityReference("uom", uom.Id);
                        orderProduct["description"] = (string)orderProductName;
                        orderProduct["tax"] = (decimal)0;
                        orderProduct["new_pricingtype"] = new OptionSetValue(((OptionSetValue)quote["new_pricingtype"]).Value);
                        orderProduct["priceperunit"] = new Money(prepayedAmount.Value);
                        orderProduct["quantity"] = (decimal)1;
                        orderProduct["new_pricingtype"] = new OptionSetValue(1);
                        orderProduct["new_ratio"] = (decimal)1;
                        orderProduct["manualdiscountamount"] = new Money(0);
                        orderProduct["new_specificdiscountpercentage"] = (decimal)0;
                        orderProduct["new_grossannualincome"] = new Money(prepayedAmount.Value);
                        orderProduct["new_gaixratio"] = new Money(prepayedAmount.Value);
                        orderProduct["new_recommendedvalue"] = new Money(prepayedAmount.Value);
                        orderProduct["new_fixedpriceplusratio"] = new Money(prepayedAmount.Value);

                        service.Create(orderProduct);
                    };
                }
            }
        }

Do you guys have any suggestions that may point me to the solution of this?

Thanks in Advance, 

Georgi B

*This post is locked for comments

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

    This forum link:  community.dynamics.com/.../314872.aspx

    has a lot of interesting information on it from Aileen

    I got the details that follow below from this blog:  missdynamicscrm.blogspot.com.au/.../10-facts-about-default-price-list-in-CRM2011-2013-that-you-might-not-have-noticed.html

    One Product only can have 1 Default Price List assigned to it.

    CRM only supports 1 Price List for each Quote by default, Once you Add Quote Product that does not exist in the Price List Item of Quote header Price List, there will be three cases that will happen:

    - If the Product does not have Default Price List value, then once you added the Product that did not exist in the Price List Item of the Quote’s Price List, you would not be able to choose The Unit and would not be able to add the Product to the Quote from other Price List, CRM only supports 1 Price List for each Quote (out of the box).

    No Product and Unit found

    - Since CRM Only support 1 Price List for each Quote, so that if the Users want to add Product from Different Price List, that Product should be having a Default Price List. You should set the Default Price List field in the Product Master setup (see picture from step 8) and make sure in the Default Price List you have the selected Product with specific unit selected from Quote Product and make sure with same currency with Price List in the Quote header. Then, now your Quote supports for ‘multiple price list’ indirectly.

    So, this is the key role of the Default Price List, that is to Enable User adding a Product that does not exist in the Quote header Price List.

    - If you have managed to add Quote Product to the Quote because currently the Product has Default Price List, later you remove the Default Price List value of that Product, if you refer back to the existing Quote Product, you will receive an error

  • Suggested answer
    Community Member Profile Picture
    on at

    Follow this post. This may have the same issue that you are facing. Hope this may help out.

    https://community.dynamics.com/crm/f/117/t/134575.aspx

  • Aileen Gusni Profile Picture
    44,524 on at

    Georgi,

    If your error is related to the Quote Product (when adding this record), you should check your Order Product plugin not the Order.

    Have you tried to debug?

    And yes you might take a look the point pointed by MSCRMBA very well.

    Thank you.

  • Community Member Profile Picture
    on at

    Thank you guys for the responses. As it turns out the problem was not in the plugin itself, but in the step that was triggering it. It was used in another plugin also, so I had to separate the plugin logic.

    Thank's again,

    Georgi B.

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans