Recently had a requirement to get all selected option texts from a multi select option set. Getting selected values is straight forward but I wanted to get the Label of selected values. For normal option set we can get it easily by using FormattedValues but that does not work with Multiselect Option set.
Then found an handy code by Ravi Kashyap that was posted on community here. I have just restructured the function to make it generic.
Now just call the getSelectedOptionSetText() function and pass Organization Service, entity name and MultiSelect optionset field name.
The function first retrieves all the labels from the Option Set and then filters it with selected option set values.
public string getSelectedOptionSetText(IOrganizationService service, Entity enRecord, string fieldName)
string selectedText = string.Empty;
// Get the Formatted Values of MultiSelect OptionSet
List multiSelectTextCollection = GetOptionSetTextCollection(service, enRecord.LogicalName, fieldName);
View original post 135 more words