CRM 2013 Updating the Quote Product section -


has tried create plugin updates record's values in quote product form? created one, because need custom formula calculates extended amount field, there automatic calculations in crm fill these fields. doesn't allow me update formula of calculation @ all.

what plugin do, is:

  1. gets values fields price per unit, quantity , discount % (which custom field);
  2. calculates value need;
  3. sets @ extended amount field.

but, none of works because "business process error"; error tells me can't use record's guid access it.

here code:

protected void executepostquoteproductupdate(localplugincontext localcontext)     {         if (localcontext == null)         {             throw new argumentnullexception("localcontext");         }          ipluginexecutioncontext context = localcontext.pluginexecutioncontext;         iorganizationservice service = localcontext.organizationservice;          guid quoteproductid = (guid)((entity)context.inputparameters["target"]).id;         columnset set = new columnset();         set.allcolumns = true;          var quote = service.retrieve("quotedetail", quoteproductid, set);         var priceperunit = quote.attributes["priceperunit"];         var teamleader = quote.attributes["new_disc"];         var manualdiscountamount = quote.attributes["manualdiscountamount"];         var volumediscountamount = quote.attributes["volumediscountamount"];         var vat = (int)quote.attributes["new_vat"];          var discountamount = (double)priceperunit * (double)teamleader / 100;         var baseamount = (double)priceperunit - discountamount;         var tax = baseamount * vat / 100;         var extendedamount = baseamount + tax;         quote.attributes["new_discountamount"] = discountamount;         quote.attributes["baseamount"] = baseamount;         quote.attributes["tax"] = tax;         quote["description"] = priceperunit;         quote.attributes["extendedamount"] = extendedamount;         service.update(quote);       } 

please, tell me if there way access fields , use/set them.

thanks in advance! :/

you cannot update extendedamount directly - instead if use built-in fields automatically calculate crm take care of you.

those fields are: baseamount, quantity, discountamount, , tax. these money fields need store them such:

quote.attributes["baseamount"] = new money(baseamount); // money , decimal numbers use "decimal" datatype , not double. 

as custom calculation, need convert percentage stored in custom field actual amount , assign discountamount attribute. like:

var discountamount = (decimal)priceperunit * (decimal)teamleader / 100; // assigning actual discount amount automatically recalculate extended amount on line. // no need recalculate fields.  quote.attributes["discountamount"] = new money(discountamount); 

note tax may need recalculated reflect discount, process should work same.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -