-1

Is there anyway I can receive a default value in Fetch XML queries

For example <attribute name="fullname" />

If in the entity "fullname" is not set in dynamics currently it's not returning the attribute. Is there any way I can receive blank in the result set?

I am using EntityCollection collection = svc.RetrieveMultiple(new FetchExpression(body.ToString()));

I don't want to check for the attribute, don't want to hardcode, in the code as it can be any attribute.

DaemonBee
  • 41
  • 6
  • Is this specific to fullname, or does it happen for other attributes as well? I recall fullname behaving differently than other attributes in some cases. – Tobias Kildetoft Sep 19 '20 at 11:44
  • fullname is just an example, it can be any attribute. – DaemonBee Sep 19 '20 at 11:50
  • But is the behavior the same for other attributes as well? also, just to make sure: When you say it is not returned, you mean that if you ask for contact["fullname"] you get an error? – Tobias Kildetoft Sep 19 '20 at 11:51
  • yes in fetch xml it's the default behaviour as I know. If any attribute is null or lank Fetch XML result doesn't return the attribute. so as per your query contact["fullname"] will be null. – DaemonBee Sep 19 '20 at 15:52
  • Being null is not the same as not having been fetched. If the value in CRM is null, then what else would you expect it to fetch? – Tobias Kildetoft Sep 19 '20 at 15:53

2 Answers2

0

This is usual and expected behavior. Just we have to check for existence and availability like below:

if (entity.Contains("fullname") && entity.GetAttributeValue<String>("fullname") != null)
{

//your logic here

}

In your iteration of EntityCollection using foreach, use the above check for every attribute of its datatype.

0

Assuming you're setting your ColumnSet to All/true.

You can query all the entity attributes separately from the metadata using the RetrieveEntityRequest Make sure to set the EntityFilter to Attributes This will retrieve all attributes from the metadata for said entity type.

Once you have the list of all existing attributes you can loop check if they exist in the returned entities in your collection if(!entity.contains(att)) => this means the value is null.

Dynamics by default doesn't return the attribute in the collection if its value is null.

Dharman
  • 30,962
  • 25
  • 85
  • 135
ef_
  • 28
  • 3