Hi,
You can use the below code to set value in a multi select OptionSet. In my below code, I am retrieving value from a multi select OptionSet present on the Account form and setting the same value in another multi select OptionSet present on a different form.
SetMultiSelect = function (executionContext) {
//Get Form Context from Execution Context
var formContext = executionContext.getFormContext();
//Get Account GUID
var accountId = formContext.getAttribute("new_account").getValue()[0].id;
//Retrieve the values of multi select OptionSet from Account entity
Xrm.WebApi.retrieveRecord("account", accountId, "?$select=new_multiselect").then(
function success(result) {
if (result.new_multiselect !== null) {
//Get Array of Selected OptionSet Values
var values = result.new_multiselect;
//Convert the retrieved string array into an integer array to set it correctly in another multi select OptionSet
var val = values.split(',').map(Number);
formContext.getAttribute("new_accountmultiselect").setValue(val);
}
},
function (error) {
writeToConsole(e.message);
});
}
To set static values you can also try:
formContext.getAttribute("new_accountmultiselect").setValue([1,2,3,4]);
Hope it helps!
Thanks
Hiteksha