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 :
Microsoft Dynamics CRM (Archived)

ISV Code Aborted the Operation - Error when retrieving a custom field from Quote Products

(0) ShareShare
ReportReport
Posted on by

Hi guys, 

I'm stuck with this for a while now, and I can't seem to find a solution for my problem so here I am asking you.

I have a field called "new_recommendedvalue" in the Quote Products, which is of type "Money". I would like to sum the "new_recommendedvalue" field for every Quote Product of the Quote, so the users could see the total amount of recommended values. 

The field should act like the Total Amount field that is already in the Quote.

What I did: From the quote I retrieved all the quotedetails which quoteid is equal to the quote that I'm in. Then I use foreach to go trough every record, and take the fields that I need. 

The problem is that when I reach the field called "new_recommendedvalue" in my code, everything is okay and the TotalSum is being calculated, until I reach the service.Update(quote), then it fires this error  "ISV Code aborted the operation".

 

 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 > 5)
            {
                return;
            }
            else
            {
                //First I get the base values that I need for the calculations

                var totalamount = (Money)quote["totallineitemamount"];
                var totalamountValue = (Money)quote["totalamount"];
                var discount = (Money)quote["totaldiscountamount"];
                var prepaymentValue = (OptionSetValue)quote["new_prepayment"];
                var VAT = (OptionSetValue)quote["new_vat"];
                var tax = totalamount.Value * VAT.Value / 100;
                var currentDetail = new Entity();

                Money SUMOfRecommendedValues = new Money();
                Money currentRecommendedValue = new Money();

                quote["new_totalammountincludingvat"] = new Money((totalamount.Value) + tax);
                quote["new_prepayedamount"] = new Money((prepaymentValue.Value * totalamountValue.Value) / 100);

                ConditionExpression condition = new ConditionExpression();
                condition.AttributeName = "quoteid";
                condition.Operator = ConditionOperator.Equal;
                condition.Values.Add(quoteProductID);

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

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

                EntityCollection quotedetails = service.RetrieveMultiple(query);

                foreach (var detail in quotedetails.Entities)
                {
                    var quantity = (decimal)detail["quantity"];
                    var priceperunit = (Money)detail["priceperunit"];
                    var teamleader = (OptionSetValue)detail["new_tldiscount"];
                    var manualdiscountamount = (Money)detail.Attributes["manualdiscountamount"];
                    var baseamount = (Money)detail["baseamount"];

                    //finally I calculate the tax
                    detail["new_vat"] = new OptionSetValue(VAT.Value);
                    var taxDetail = (baseamount.Value - manualdiscountamount.Value) * VAT.Value / 100;
                    detail.Attributes["tax"] = new Money(taxDetail); //tax

                    service.Update(detail);
                    //I retrieve the new_recommendedvalue after the detail is updated because I don't want to update it
                    currentRecommendedValue = (Money)detail["new_recommendedvalue"];
                    SUMOfRecommendedValues.Value += currentRecommendedValue.Value;
                }

                quote["description"] = (new Money((SUMOfRecommendedValues.Value) + tax)).Value.ToString();

                service.Update(quote);
            }



And that was the code inside the plugin.

Thanks in advance!

Georgi B.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    There is some code which is throwing exception, do you have any other plugin on update ?? You can also try to put your code under try and catch block using

    try{}

    catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex){}

    then you can check for detail error, maybe you will get more details about the process which is throwing exception.

    You can also try to check on CRM logs if you have enabled tracing or you can also try to check in event viewer.

  • Community Member Profile Picture
    on at

    Thank you, Mahendar!

    It did interfere with another plugin. Now that I know where the problem is It'll be easier to solve the problem myself.

    Regards, 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

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans