views:

1150

answers:

2

Hi,

I am trying to retrieve the display value of a lookup field in a plugin for MS Dynamics CRM 4.0. The value of the attribute is a GUID which points to another entity (owner of salesorder in this case). "Normal" attributes I retrieve with a code like this:

CrmDateTime  serviceOrderDateDT = (CrmDateTime)entity["submitdate"];
                      serviceOrderDate = serviceOrderDateDT.Value.ToString();

Any ideas on how to do this for the display value of a lookup field?

+1  A: 
Lookup ownerLookup = (Lookup)entity["ownerid"];
string ownerName = ownerLookup.name;
Matt
Thanks for your reply. When I do this I get : "the given key was not present in the dictionairy". My salesorder does have a owner offcourse! Any ideas?
AaronTjong
You need to make sure ownerid is in your column set when you retrieve the entity.
benjynito
A: 

Actually, you need to cast that property to type Owner not Lookup, i.e.: (Owner)entity["ownerid"]

sander