Thursday, November 5, 2020

Dynamics 365 - How to Get Selected Count of Multi-Select Picklist

Lets take an example of a multi-select picklist having 5 values: 

  1. Banana
  2. Orange
  3. Strawberry
  4. Guava 
  5. Grapes
While working on the form, if a user selects only 2 out of these, e.g: 

  1. Banana
  2. Guava

Following JavaScript will return the count of selected values in the multi-select picklist i.e. 2

function GetMultiSelectPicklistLength(executionContext)
{
var length = 0;
var formContext = executionContext.getFormContext();
var multiSelectField = formContext.getAttribute("new_MultiselectPicklist");
if(multiSelectField != null)
{
var fieldValue = multiSelectField.getText();
if(fieldValue != null)
{
lengthValue = fieldValue.length;
}
}
return length;
}


No comments:

Dynamics 365 - Dynamically Add / Remove Values from a Multi-select Picklist

Following code can be used to dynamically remove a particular value from a multi-select option set: function RemoveValuefromMultiSelectOptio...