2

I'm trying to get the fields of a parent entity, but I don't get all the fields, only some of them.

Entity parentEntity = service.Retrieve("entityname", id, new ColumnSet(true));

While debugging, I see some of the customly defined attributes of the custom entity in the returned entity, but some of them are missing. For example, I'm getting the integer values of the option lists, but not the value of a value field. There's no such property in the retrieved entity.

It is a plugin that fires post update event.

Any help will be appreciated. Thanks.

tdgtyugdyugdrugdr
  • 786
  • 4
  • 13
  • 31
  • 1
    How do you get your attributes? with the postImage or with the target? Because if you are retrieving them from the target, it might be that they haven't changed in the CRM, and therefor are not in the Target because it only contains attributes that have been changed. – Yacine Zine Sep 17 '12 at 10:12
  • Hello. I got the Guid (foreign key to the parent obj) from the postimage, and used it to get the parentEntity as shown above. The parent entity is missing some attributes. – tdgtyugdyugdrugdr Sep 17 '12 at 10:33
  • and in the plugin registration tool. Did you define your postImage with all available attributes? It could be that they are empty so you can not retrieve anything. – Yacine Zine Sep 17 '12 at 11:13
  • Thank you for your time, the issue has been solved. The problem was that the actual field was null, I thought I'd still get the field with a null value, apparently in this case you don't even get the field. Cheers! – tdgtyugdyugdrugdr Sep 17 '12 at 13:01

1 Answers1

7

You will only get attributes that have been populated (that have a value in the database).

The attributes collection may contain some other bits as well, such as system values and the Id, but for standard fields generally speaking you only get the fields which have value returned.

For example if you have a contact record with the following data:

First name: James Last name: Wood

Then:

Entity contact = service.Retrieve("contact", contactId, new ColumnSet(true));

contact.Attributes will contain 'firstname' and 'lastname'. But wont contain 'middlename'.

(As a side using new ColumnSet(true) should generally be avoided when you can).

James Wood
  • 17,286
  • 4
  • 46
  • 89
  • Great thanks! I was trying an update operation and couldn't get the field. I just set the null value to zero (as it should be) and now everything works like a charm! – tdgtyugdyugdrugdr Sep 17 '12 at 12:59