locked
option set and lookup value in Plugin in CRM 2013 RRS feed

  • Question

  • Hi,

    I have created a plugin for validation.

    how can i get the option set and lookup's value in my Plugin.

    Thanks


    Monday, April 7, 2014 7:58 AM

All replies

  • Give this a try

    OptionSetValue optionState = currEntity .Attributes["statecode"] as OptionSetValue;
    
    statusValue = optionState.Value;
    
    statusText = optionState.Text;

    Good Luck :)


    Monday, April 7, 2014 8:46 AM
  • Hi,

    I have tried but below line throwing error that does not contain defination "Text".

    statusText = optionState.Text;

    Monday, April 7, 2014 10:47 AM
  • Hi,

    In plugin you wouldn't get 'Text' property of OptionSetValue object. there is no such property. You have to deal with 'Value'.

    OptionSetValue optionState = currEntity .Attributes["statecode"] as OptionSetValue;
    
    statusValue = optionState.Value;

    For lookup use EntityReference type.

    EntityReference  lookupAttribute  = (EntityReference)currEnitty.Attributes["lookupAttriburename"];

    Guid id = lookupAttribute.Id;

    string name = lookupAttribute.Name;

    string entityName = lookupAttribute.LogicalName;

    Thanks

    Kuldeep

    Monday, April 7, 2014 3:45 PM