Search This Blog

Sunday, January 15, 2023

SELECT ALL OPTIONS OF MULTISELECT OPTION SET (CHOICES) FIELD IN DYNAMICS 365

 

Multiselect or Choices field type has some limitations when working with them. One of these limitations is to select all the options by default.

Since the multiselect fields cannot be used in business rules, therefore, you have to go with JavaScript to achieve this need.

For this post, we will see how to select all options of a Multiselect / Choices field in Dynamics 365.

  1. The below code snippet will get all the available options in the multiselect field and will select them all
    // Select all the options in the multiselection field on create form
    function setMultiselectDefaultValues(context) {
    var formContext = context.getFormContext();
    if (formContext.ui.getFormType() === 1) {
    var options = formContext.getAttribute("cak_multiselectoptionfieldcode").getOptions(); // Get all the available options
    var selectOptions = [];
    for (var i = 0; i < options.length; i++) {
    selectOptions.push(options[i].value); // Add the options into an array
    }
    formContext.getAttribute("cak_multiselectoptionfieldcode").setValue(selectOptions);
    }
    }


    Multiselect options
  2. Create your JavaScript web resource and add it to the needed solution
  3. From the form onLoad event, call the specific function

No comments:

Post a Comment