Question

Here is the point I'm at. new_TotalAssets is defined in tsql as Money, as Dynamics CRM defined it. I need to convert it to decimal so I can add another value to it and update the value back in tsql. When I tried to do that with all money fields, I got the error: Operand + cannot be applied to operands of type 'Microsoft.Xrm.Sdk.Money' and 'Microsoft.Xrm.Sdk.Money'. What is the correct way to make this work?

Decimal TotA = decimal.Parse("0.0000");
Entity opp = service.Retrieve("opportunity", Guid.Parse(oppid), new ColumnSet(new string[] { "new_totalassets" })); // no runtime error here

//TotA = (Decimal)opp.Attributes["new_totalassets"];                        // specified cast is not valid
//TotA = Convert.ToDecimal(opp.Attributes["new_totalassets"]);              // Unable to cast object of type 'Microsoft.Xrm.Sdk.Money' to type 'System.IConvertible'.
//TotA = Convert.ToDecimal(opp.Attributes["new_totalassets"].ToString());   // input string was not in a correct format
//TotA = Decimal.Parse(opp.Attributes["new_totalassets"].ToString());       // input string was not in a correct format
Was it helpful?

Solution

Before summing up the data please try to use .Value of the attribute. Something like this,

decimal totalValue=((Money)opp.Attributes["new_totalassets"]).Value;

Now use the totalValue for the summing up or any other operations as required.

Hope this helps!!!

OTHER TIPS

Convert.ToDecimal(opp.GetAttributeValue<Money>(item).Value);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top