Skip to content

Script Data Source

This data source executes a script and returns the result as a list of values.

The script data source enables the execution of custom scripts to dynamically generate data for form controls.

The script's result must be an array of objects, each defining the properties of an option within the list of values.

The script also supports asynchronous operations using async/await patterns. The script is expected to complete within a 500ms duration; otherwise, a progress dialog will be displayed to the user.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<ScriptDataSource TextFormat="{{name}}" ValueFormat="{{value}}">
    <Mappings/>
    <Source>
        <Content><![CDATA[

return [
    {
        name: 'A',
        value: 1
    },
    {
        name: 'B',
        value: 2
    }
];

]]></Content>
    </Source>
</ScriptDataSource>

In this example:

  • TextFormat is set to {{name}}, indicating that the name property within each object returned by the script will be used for display text.
  • ValueFormat is set to {{value}}, specifying that the value property within each object will be used as the underlying value.
  • The Source element contains the Content element, which encapsulates the script to be executed.
  • The script is a simple JavaScript code block that returns a static array of two objects. Each object has name and value properties, which will be used to populate the data source.

In summary, this data source will execute the provided JavaScript code, which will generate a list of two items. The first item will have a display text of "A" and a value of 1, and the second item will have a display text of "B" and a value of 2.