The easiest way to get the Label for the option set in plugin is using the FormattedValues property of the Entity.
The Post Create plugin on Contact record getting the label for the address type field.
if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is Entity){
// Obtain the target entity from the input parmameters.
Entity entity = (Entity) context.InputParameters[“Target”];
if(entity.Contains(“address1_addresstypecode”)){
string addressTypeCodeLabel = entity.FormattedValues[“address1_addresstypecode”];
entity.Attributes[“address1_city”] = addressTypeCodeLabel;
service.Update(entity);}
}
Hope it helps.
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();
(Set) Post OptionSet Value : –
newSalesOrder[attributeName] = new OptionSetValue(Convert.ToInt32(optionValue));
LikeLike
I couldn’t get the formatted values of option set in context. context only has the integer value of the optionset
LikeLike