Milos Nikolic Milos Nikolic - 3 months ago 7
C# Question

Check if data is retrieved - CRM

I am retrieving data from CRM. I want to retrieve few fields from

quotedetail
. One of them is a
int
field
ad_discountpercent
.

This field doesn't necessary have a value.

I need to check if there is some value retrieved from that field and give it a default value
0
if there is no value.

Here is my code:

string fetch1 = @"
<fetch count='50' >
<entity name='quotedetail' >
<attribute name='manualdiscountamount' />
<attribute name='priceperunit' />
<attribute name='ad_discountpercent' />
<attribute name='quantity' />
<attribute name='extendedamount' />
</entity>
</fetch>";

EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetch1));

foreach (var c in result.Entities)
{
if(...)
}


What should I put instead of
(...)
to see is there any data retrieved and give a default value? It would be helpful if you know and of these two things.

Lett me know if you need some additional info.

Answer

To access field value you can use GetAttributeValue<T>(string attribute logical name)

In your case:

c.GetAttributeValue<Entity>("ad_discountpercent");
Comments