How to assign values to a multichoice component using a scriptCode

How can I set a multichoice domain with a script? How to add items to selected ones?

The multichoice script must return an array of objects that have the following values:

id - id of an item
text - description of an item
a flag that indicates if it is selected e.g. isSelected

Example values:

const result = [
        {
            "id" : "id1", 
            "text" : "Value1", 
            "isSelected" : true
        }, 
        {
            "id" : "id2", 
            "text" : "Value2", 
            "isSelected" : false
        },
        {
            "id" : "id3", 
            "text" : "Value3", 
            "isSelected" : false
        }
    ]
    return result;

The output parameters of the above script are id, text, isSelected.

Currently, we can only define a multichoice component in the source (xml)
An example of connecting the script to multichoice would look like this:

<data:ExternalDataSource name="test_script" type="SCRIPT_SERVICE" changesWidgetAttributes="false" condition="" version="Current version">
            <data:OutputFields>
              <data:Field id="aea7e5a6-7164-4ee3-8aad-b4b62b682105" localName="id" serviceName="id"/>
              <data:Field id="53ababf7-14dc-489c-a7ac-440064705273" localName="text" serviceName="text"/>
              <data:Field id="a4b627b8-5b2d-4eec-93f2-849498ddc0f8" localName="selected" serviceName="isSelected"/>
            </data:OutputFields>
          </data:ExternalDataSource>
1 Like