Multichoice external data sources as script

How can I set a multichoice domain with a script? How to assign a value to multichoice?

As you probably know, at the moment you can declare multichoice from the source level. So to connect the script you need to add the “External data source” tag with the appropriate parameters:

  • name of the script
  • type - data source type (in this case SCRIPT_SERVICE)
  • and attributes with default values as below
<data:ExternalDataSource name="test_script" type="SCRIPT_SERVICE" changesWidgetAttributes="false" condition="" version="Current version">
   <data:OutputFields>
      <data:Field localName="id" serviceName="id"/>
      <data:Field localName="text" serviceName="text"/>
      <data:Field localName="selected" serviceName="selected"/>
   </data:OutputFields>
</data:ExternalDataSource>

In order for the component to be connected correctly, you need to map the outputs from the script with its parameters using OutputFields, where localName is the name of the component parameter, and serviceName is the name of the output from the script.

The script should return an array containing objects with parameters:

  • id - value key
  • text - label of individual elements
  • selected - a flag that determines whether a value is checked or not

Example script:

function callService(context) {
    const result = [
        {
            "id" : "id1", 
            "text" : "Value1", 
            "selected" : true
        }, 
        {
            "id" : "id2", 
            "text" : "Value2", 
            "selected" : false
        },
        {
            "id" : "id3", 
            "text" : "Value3", 
            "selected" : false
        }
    ]
    return result;
}

Remember to declare the output parameters correctly
image