How to work with MultiSelect Option Set Fields in Dynamics 365 v9 | R.iT News-Blog
11.03.2020 One of them is the MultiSelect Option Set with attributes of the type OptionSetValueCollection. This makes it possible to select more than one value of a picklist and additionally to search for individual options or a combination of these. The option to search for values can help, as you can enter up to 150 options in this field. All selected values separated by semicolons and displayed in alphabetical order. In Figure 1you can see the representation of this field type. Adding this field to an entity works as before. It is simply a new field type to select. Here you can insert options as usual. It is also possible to use one global optionset for both, a MultiSelect Option Set and a simple Option Set. There are still small differences. For example, there is no way to set a default value during creation.
You can use the MultiSelect Option Set Field as usual in the search query. If the operators “equal” or “not equal” are used it only searches for records which exactly fit. In Figure 1 is “abstract thinking;patience” selected. I can find this record if I search for exact this combination but not if I search for “equals abstract thinking, patience, logic” or for “equals patience”. As you can see, it is important to choose the right operator for your search. If you do not want an exclusive match it is better to use the operators “contain values/not contain values”.
if(executionContext === undefined) throw “No execution context existing.”;
var context = executionContext.getFormContext();
var mplValues = context.getAttribute(“rit_programmingskills_mpl”).getValue();
var mplValuesAsText =
C# Plugins and MultiSelect Option Sets
So how does it work with a C# plugin? I just want to give you a short view. To get the values we need to get the associated entity. I will call it myEntity. We can get the attributes as an OptionSetValueCollection as you can see in Code Snippet 3. The variable myFieldName must be a MultiSelect Option Set field. Then you can query all values with a foreach loop. OptionSetValueCollection values =
foreach (var option in values)
int value = option.Value;
} To set values just create an own OptionSetValueCollection and add OptionSetValues. Take care to use the integer values. This collection can then be assigned to the corresponding field as usual and updated or created by the IOrganizationService.
Originally published at https://www.rit.de.