I want to null check for money field in .net MVC web services how to null check I write this but i don't get answer
//create module
public Money Amount { get; set; }
//Null Check
if ((EntityObject.Amount) != null)
{
object Entity.Attributes.Add("budget amount", EntityObject.Amount);
}
How I write null check at Money field?
Entity.GetAttributeValue<T> Method (String)
is good to avoid nulls, but please be careful that it will returnDefault values
for some data types.http://www.crmanswers.net/2015/04/getattributevalue-demystified.html https://msdn.microsoft.com/en-us/library/gg326129.aspx
if you are using Late bound
Entity
class, then you can do as below:Before checking for null value, make sure you have retrieved the attribute in your Query like below:
// Retrieve the account containing several of its attributes.
https://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.iorganizationservice.retrieve.aspx
Money is a special datatype, you have to handle like below using
GetAttributeValue
.