0

i want make query expression in which one column contain values or it will be blank or null according to condition. Example - contact entity

firstName | LastName | Address1

name1 | lastname1 |
name2 | lastname2 | address

name3 | lastname3 | address2

Now i want to replace those blank column to 'NA' In sql we can write query like this -

select isnull(address1,'NA') as address from contact

I want write same query in query expression

yogs
  • 23
  • 1
  • 9
  • thanks for your reply but i want null value replaced in select column like sql – yogs Jul 22 '16 at 12:33
  • You're asking about QueryExpressions which is just a method for formulating a query to CRM. This will return an entity collection. Are you asking how to have the Attributes of the entities have a null value, since by default, CRM doesn't populate the attribute at all? – Daryl Jul 22 '16 at 16:38

1 Answers1

0

It is not possible to get fetchxml to replace the value for you server side. But why don't you change the attribute values after they are fetched? You would end up with the same result

const string defaultValue = "NA";
var result = service.RetrieveMultiple(queryExpression);

foreach (var entity in result.Entities)
 {
      if (!entity.Attributes.ContainsKey("address1"))
      {
         entity.Attributes.Add(new KeyValuePair<string, object>("address1", null));
      }
      entity["address1"] = entity["address1"] ?? defaultValue;
  }
dynamicallyCRM
  • 2,980
  • 11
  • 16
  • Thanks for your reply. I am picking only 5 records in grid from DB with the help of paging cookie so it wont be possible to use above solution. – yogs Jul 25 '16 at 05:58
  • And what exactly is the problem with choosing 5 records or 500 records? If all you want is for null attributes to have a default value, the above solution will work. – dynamicallyCRM Jul 25 '16 at 16:05