Answered by:
crm2011 - plugin - post sync calculate tax not working

Question
-
We're trying to calculate tax using a plugin, it's registered on invoicedetail (update message, synchronous, post operation).
Entity invoiceDetail = sdk.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet("extendedamount", "tax"));
if (invoiceDetail != null)
{
var taxPercent = 15m;
var extendedAmount = invoiceDetail.GetAttributeValue<Money>("extendedamount"); // this is always null
var existingTax = invoiceDetail.GetAttributeValue<Money>("tax");
if (extendedAmount != null && existingTax != null)
{
decimal tax = (extendedAmount.Value - existingTax.Value) * (taxPercent / 100);
Entity update = new Entity(entity.LogicalName);
update[entity.LogicalName + "id"] = entity.Id;
update["tax"] = new Money(tax);
sdk.Execute(new UpdateRequest { Target = update });
}
}It seems extendedamount is always null?
This worked fine for CRM 4 but in 2011 it's broken. I posted this question awhile back on the beta forum and Michaels' answer didn't work, now that thread is gone but still on googles' cache http://webcache.googleusercontent.com/search?q=cache:GOYn9_nim-cJ:social.microsoft.com/Forums/en-MY/crm2011beta/thread/00d54531-9371-4bac-9441-87c70492bdd6+crm+2011+post+synchronous+tax&hl=en&gl=nz&strip=1
Any ideas?
Wednesday, April 20, 2011 11:04 PM
Answers
-
In CRM 2011 Quote and Order Product (quotedetail & orderdetail) have some fields which will be calculated automatically and filled by the CRM system in this case when we are creating the record it will just create a record with the filled values in the form and after that it will run a update again for achieving the automatic calculation and in this update process only the CRM system will be automatically calculating the values and filling the specified fields
1) When we Create Quote Product (quotedetail Entity) means when we add a product to the quote the plugin registered in CREATE Message of quotedetail entity will be triggered first and after that the plugin registered in the update message will be triggered.
2) In the Create message it will be just creating a quotedetail entity record with the filled values and in the update message it will be doing the automatic calculation and filling all the columns so if you want to get the calculated values in your plugin we have to register our plugin in update message as postoperation
With Regards Athul MT- Proposed as answer by Athul MT Tuesday, February 7, 2012 7:15 AM
- Marked as answer by JLattimerMVP, Moderator Wednesday, January 16, 2013 7:54 PM
Friday, February 3, 2012 8:31 AM
All replies
-
Where is the variable "entity" defined?Thursday, April 21, 2011 2:00 PM
-
once your plugin executed sucessfully and then only the extended amount will be automatically calculated by the CRM system
so that you have to retrieve the needed values and has to calculate everything in the plugin and you have to set the "tax" column value
With Regards Athul MTMonday, January 30, 2012 12:58 PM -
I suggest you to replace your soap request by a Post-Image registered on your plugin update step. (performance question/best practices)
Virtual Group - Soluções Inteligentes www.virtualgroup.com.brMonday, January 30, 2012 1:42 PM -
In CRM 2011 Quote and Order Product (quotedetail & orderdetail) have some fields which will be calculated automatically and filled by the CRM system in this case when we are creating the record it will just create a record with the filled values in the form and after that it will run a update again for achieving the automatic calculation and in this update process only the CRM system will be automatically calculating the values and filling the specified fields
1) When we Create Quote Product (quotedetail Entity) means when we add a product to the quote the plugin registered in CREATE Message of quotedetail entity will be triggered first and after that the plugin registered in the update message will be triggered.
2) In the Create message it will be just creating a quotedetail entity record with the filled values and in the update message it will be doing the automatic calculation and filling all the columns so if you want to get the calculated values in your plugin we have to register our plugin in update message as postoperation
With Regards Athul MT- Proposed as answer by Athul MT Tuesday, February 7, 2012 7:15 AM
- Marked as answer by JLattimerMVP, Moderator Wednesday, January 16, 2013 7:54 PM
Friday, February 3, 2012 8:31 AM