Hi,

  Below is the sample code to read Picklist value (i.e., OptionSet Value) in CRM 2011

if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] isEntity)

{

currEntity = (Entity)context.InputParameters[“Target”];

}

int statusValue = -1;

string statusText=string.empty;

if (currEntity .Attributes.Contains(“statecode”))

{

OptionSetValue optionState = currEntity .Attributes[“statecode”] as OptionSetValue;

statusValue = optionTimesheetState.Value;

statusText = optionTimesheetState.Text;

}

Hope it helps 🙂

Advertisements
Advertisements

7 responses to “Read Optionset value in Plugin CRM 2011”

  1. ashishsharmaengg Avatar

    Great it is working ….

  2. Rokas Avatar
    Rokas

    Thanks, it works 🙂

  3. BRMD Avatar
    BRMD

    Thanks for your post but I don’t find The “Text” method…

    1. Debbie Avatar
      Debbie

      I’m also receiving the “does not contain a definition for ‘text’” error. What am i missing?

      1. Jack Avatar
        Jack

        Me too I have the same issue with Text. Did you find a solution please?

  4. Jack Avatar
    Jack

    Here is a very good solution to retrieve optionSet Text when you have the value and vice versa : https://community.dynamics.com/crm/b/mshelp/archive/2012/06/12/get-optionset-text-from-value-or-value-from-text.aspx

  5. saddamk Avatar

    Hi,

    There are two way to get text of OptionSet:-
    First:-

    OptionSetValue opProductType = new OptionSetValue();

    opProductType = (OptionSetValue)item.Attributes[attributeName];

    var optionValue = opProductType.Value;

    Second:-

    var StatusString = TermAndCon.FormattedValues[attributeName].ToString();

    Post OptionSet Value : –

    newSalesOrder[attributeName] = new OptionSetValue(Convert.ToInt32(optionValue));

Leave a reply to BRMD Cancel reply