Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Option set value in CRM 2011?

I have an Option set in CRM 2011. It has four options:

  1. Public
  2. Private
  3. Subsidiary
  4. Other

Through plugin I want to set the value of this option set. Can anyone provide me the statement to set the value of this option set?

like image 664
aanch Avatar asked May 04 '12 05:05

aanch


People also ask

Where the option set field options are stored in CRM?

These are all stored in the StringMapBase table.

What is option set in CRM?

An option set is a type of field that can be included in an entity. It defines a set of options. When an option set is displayed in a form it uses a drop-down list control.

How to set optionset value in crm using c#?

We use enum to achieve it. public enum Gender { Male = 864630000, Female = 864630001, }; my_optionSet = new OptionSetValue((int)Gender. Male); These are going to be pre-defined key:value pairs that never changes between environments.


2 Answers

How to set optionsetvalue in plugins

In plugins you can write yourEntity.yourAttribute = new OptionSetValue(INDEX); The INDEX is an int you can look up in your optionset editor (default values are several digit long).

OR

You set the optionset like yourEntity.Attributes.Add(“yourAttribute”, new OptionSetValue(INDEX));

like image 176
gabore Avatar answered Oct 09 '22 05:10

gabore


You can set an option set value using the following:-

OptionSetValue myOptionSet = new OptionSetValue();
myOptionSet.Value = xxxx  
myEntity.Attributes["optionSetAttributeName"] = myOptionSet;

// Where xxxx represents the value desired and can be checked on the attribute metadata page within the entity customisations

Whether 'myEntity' is actually preImage/postImage or just a dynamically created entity in the plug-in will determine whether you need to actually call the update method, but essentially this is the way you set the option set value and update the attribute.

like image 8
Philip Rich Avatar answered Oct 09 '22 05:10

Philip Rich