Get and Set Multiselect Option set field values through Javascript

Day to Day Dynamics CRM going very interestingly with lot of exciting features. One of the interesting features is Multiselect Optionset Field. Through this new datatype we can set multiple option values.

Datatype : MultiSelect Option Set

3.png

  • Pass Execution Context as a Parameter.

getValue / getText:

Get.png

function GetMultiSelect(executionContext) {
var formContext = executionContext.getFormContext();

//Returns Array of Selected OptionSet Values: [1001,1002,1005 ]
var selectedValues = formContext.getAttribute("gb_multiselect").getValue();

//Returns Array of Selected OptionSet Text: ["One", "Two","Six"]
var selectedTexts = formContext.getAttribute("gb_multiselect").getText();
}

SetValue:

function SetMultiSelect(executionContext) {
var formContext = executionContext.getFormContext();
//Option values with comma separates
//Overwrites the Existing Selected Values
formContext.getAttribute("gb_multiselect").setValue([1003,1004,1006]);
}

set.png

That’s. It. Enjoy 🙂

5 thoughts on “Get and Set Multiselect Option set field values through Javascript

  1. I am trying to set the multiselect option set values using the above code, its not working.
    var selectedValues = formContext.getAttribute(“multiselect”).getValue();
    console.log(” Value: ” + selectedValues);

    var selectedTexts = formContext.getAttribute(“multiselect”).getText();
    console.log(” Value: ” + selectedTexts);
    formContext.getAttribute(“multiselect”).setValue([1000,1001]);

    I am trying to update this field on change of another field. Also I don’t have any business rules set on the multiselect option field.

    Kindly help!

    Like

  2. when we set values of multiselect option set in javascript, the options gets selected, I want non of them gets selected at UI when setting values in javascript any property you know ?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s