locked
How to get optionset value in CRM2011 plugins/?? RRS feed

Answers

  •  

     Hi Prashant,

    Try Below

    int optionsetvalue= entityname.GetAttributeValue<OptionSetValue>("fieldname").Value;

    Thanks,

    -Anand

    Friday, September 7, 2012 2:31 PM

All replies

  • Hi Prashant,

    string optionSetValue=<enitty>.FormattedValues["optionSetname"].ToString();

    Please try this.


    Thanks, Prakash Omer Ignify | Email: prakash.omer@hotmail.com

    Friday, September 7, 2012 11:21 AM
  • Hi prakash,

              Thanks for reply prakash but its not working!Please suggest me any more.

    Friday, September 7, 2012 11:36 AM
  • What is the use case/scenario for the your plugin code?  When you say OptionSet Value, are you looking for the Index Value, Text of the selected OptionSet, the list of values available for the optionset?

    If you're using a plugin, remember only fields that have changed are sent into your "Target" input parameter for create/update.  If the option set you're looking for was not populated on create or was not changed on update, then Prakash code wouldn't work because the attribute is not in the collection.

    In addition to Prakash code that retrieves the display value for a selected optionset value the code below will give you the integer value:

    OptionSetValue _value = <entity>["optionSetName"];
    _value.Value --> This is the int value now

    Also, this assumes that you have already cast the InputParameters["Target"] attribute to an Entity in your code.

    Jeremy


    Jeremy Winchell
    Avtex
    Visit the Avtex Blog

    Friday, September 7, 2012 1:22 PM
  • since you have not disclosed the senario, i given the code.

    my code will give you the text value of the option set if it is selected on the primary entity on which plugin is firing.

    if option set is blank then you will not get that field in the entity attributes as Jermy already told you.

    for the safe side you can go for :

    if(entity.contains("attribute"))

    {

    string optionSetValue=entity.formatedValue["attribute"].tostring();

    or

    int optionSetValue=((OptionSetValue)entity["attribute"]).Value;

    }

    You can go for either option.


    Thanks, Prakash Omer Ignify | Email: prakash.omer@hotmail.com

    Friday, September 7, 2012 1:50 PM
  •  

     Hi Prashant,

    Try Below

    int optionsetvalue= entityname.GetAttributeValue<OptionSetValue>("fieldname").Value;

    Thanks,

    -Anand

    Friday, September 7, 2012 2:31 PM