Milos Nikolic Milos Nikolic - 1 year ago 75
C# Question

Check if data is retrieved - CRM

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

. One of them is a

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
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' />

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

foreach (var c in result.Entities)

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 Source

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

In your case:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download