I have an option installed in CRM 2011. It has four options:
Through the plugin I want to set the value of this option. Can someone provide me with instructions for setting the value of this option?
How to set parameter value in plugins
In the plugins you can write yourEntity.yourAttribute = new OptionSetValue(INDEX); INDEX - this is an int that you can find in your parameter editor (the default values are a few digits).
yourEntity.yourAttribute = new OptionSetValue(INDEX);
OR
You set the parameter set as yourEntity.Attributes.Add("yourAttribute", new OptionSetValue(INDEX));
yourEntity.Attributes.Add("yourAttribute", new OptionSetValue(INDEX));
You can set the parameter value using the following: -
OptionSetValue myOptionSet = new OptionSetValue(); myOptionSet.Value = xxxx myEntity.Attributes["optionSetAttributeName"] = myOptionSet;
// xxxx
, myEntity preImage/postImage , , , .
It seemed to me that I would share some code for handling sets of options in CRM here ...
fieldValue = ((OptionSetValue)entity.Attributes[field]).Value.ToString(); //need to get Option Set display label based on its value. This requires getting attribute metadata RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest { EntityLogicalName = entity.LogicalName, LogicalName = field, RetrieveAsIfPublished = true }; RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)orgContext.Execute(attributeRequest); EnumAttributeMetadata attributeMetadata = (EnumAttributeMetadata)attributeResponse.AttributeMetadata; foreach (OptionMetadata om in attributeMetadata.OptionSet.Options) { if (om.Value == ((OptionSetValue)entity.Attributes[field]).Value) { fieldlabel = om.Label.UserLocalizedLabel.Label; } } return fieldlabel;