1
votes

I've created Multi-select option-set field (category) in Dynamics CRM on-premise for Contact and Projects. Now using button click I'm trying to set the value of multi-select field on Project. But each time I am coming across with Error:

Error converting value 920650008 to type System.Collections.Generic.List 1[System.Int32].

Since the multi-select optionset field is global so there is no chance of specified values available or not.

Here is what I am trying previously:

var name = formContext.getAttribute(new.account_metada.CompanyName).getValue();
var entityFormOptions["entityName"] = "new_projects";
    entityFormOptions["openInNewWindow"] = true;
var formParameters["new_company"] = id; 
    formParameters["new_companyname"] = name;
    formParameters["new_category"]  = formContext.getAttribute("new_category").getValue()

    Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
                function (success) {
                    console.log(success);
                },
                function (error) {
                    console.log(error);
                });

Please let me know how to can I set value of multi-select optionset using Xrm.Navigation.openForm

2
var multiSelectOptionSet = formContext.getAttribute("new_category").getValue(); Debug and check whether multiSelectOptionSet returns Array. If it does then formParameters["new_category"] = multiSelectOptionSet This shall help. Also for testing you can pass hardcode array values of Multiselect to check if all works properly.AnkUser

2 Answers

1
votes

I got fix the issue by replacing below source code line:

Existing

formParameters["new_multiselectpicklist"] = formContext.getAttribute("new_multiselectpicklist").getValue();

Updated

formParameters["new_multiselectpicklist"] = "["+formContext.getAttribute("new_multiselectpicklist").getValue()+"]";

1
votes

I tested this personally and getting the same error result with the below snippet. Though the syntax is right - Something could be wrong with the Xrm.Navigation.openForm() method or this could be expected behavior because of unsupported Array datatype.

var entityFormOptions = new Array();
entityFormOptions["entityName"] = "my_entity";
entityFormOptions["openInNewWindow"] = false;

var formParameters = new Array();
formParameters["new_multiselectpicklist"]  = formContext.getAttribute("new_multiselectpicklist").getValue();

Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
                function (success) {
                    console.log(success);
                },
                function (error) {
                    console.log(error);
                });

Even a hard code assignment getting the same error:

formParameters["new_multiselectpicklist"]  = [962080001, 962080002];

Edit:

The above line should be like this to make it work.

formParameters["new_multiselectpicklist"]  = "[962080001, 962080002]";

I tried this alternate option using extraqs and it worked.

https://mycrmdev.crm.dynamics.com/main.aspx?etn=my_entity&pagetype=entityrecord&extraqs=new_multiselectpicklist=[962080001, 962080002]