Options
- Last UpdatedJun 25, 2024
- 3 minute read
Use scripts for the Options property to add options (options text and options value) for a Check Box, Drop-down, Radio Button, or List control.
Although JavaScript is used for scripting, the return value of the Options script is specified in JSON (JavaScript Object Notation) string format with attribute–value pairs.
To add options for a Check Box, Drop-down, Radio Button, or List control
-
Code the script as follows for the Options property of a Check Box, Drop-down, Radio Button, or List control:
// Name is the Text Parameter and ID is the Value Parameter.
return [{"Name":"India","ID":"1"},{"Name":"UK","ID":"2"},{"Name":"USA","ID":"3"}];
Note:
- The options Text and Value parameters are mandatory and must be unique across all options.
- Text Parameter and Value Parameter properties must be specified before using the Options property script.
- Ensure that the value for the Value Parameter property is either String or Integer.
- If you add values using both Options List and Options script, then the values added using Options script takes precedence.
- If you add options using scripts, then the value for the selected options persists even when
the options are changed.
- To ensure no values are persisted, you need to explicitly clear the values before
changing the options as given below.
control.value = "";
- If you explicitly clear the values, then the On Data Change event is triggered.
- Ensure the script returns a value.
To add options using Data Grid Values
You can add options for a Check Box, Drop-down, Radio Button, or List control using the values from a Data Grid control. To do this, first set the Text Parameter and the Value Parameter for the options of the control with the corresponding column name in the Data Grid control, and then code the script as follows:
When the Behavior property of Data Grid control is set as Data Grid
// G1 is the Data Grid whose values are used in the options of the control.
If(control.findById("G1").source.options)
{
return control.findById("G1").source.options.data;
}
When the Behavior property of Data Grid control is set as Data Source
// G1 is the Data Grid whose values are used in the options of the control.
return control.findById("G1").source;
Note: We recommend to set the Execution Mode property of Data Grid control to Synchronous when the Behavior property of Data Grid control is set to Data Source and used in Options script.
To add options using Ajax function
You can add options for a Check Box, Drop-down, Radio Button, or List control using the ajax (Asynchronous JavaScript and XML) function.
Example
If you want to add options, which include country name and ID, to the Country (D1) control, then first code the options information in the JSON attribute-value pair format as follows for the following options text and value, and save the file as CountryName.json in the BPMUITEMPLATES\Default\ folder.
[{"Name":"India","ID":"1"},{"Name":"UK","ID":"2"},{"Name":"USA","ID":"3"}]
|
Options Text Parameter |
Options Value Parameter |
|---|---|
|
Name |
ID |
|
Options Text |
Options Value |
|---|---|
|
India |
1 |
|
UK |
2 |
|
USA |
3 |
Then, code the script as follows for the Options property of the Country (D1) control:
var resultData;
$.ajax(
{
type: "GET",
url: "CountryName.json",
contentType: "application/json; charset=utf-8",
async: false
,
dataType: "json",
timeout: 10000, //10 Seconds
// CountryName.json file located in the BPMUITEMPLATES\Default\ folder
// contains options information in the JSON attribute-value pair format.
success: function (result)
{
resultData = result;
// alert("Success Message :: " + result);
},
error: function (err)
{
alert("Failure Message :: " + err);
}
}
);
return resultData;
Note:
- If all the parameters in the script are not represented as strings (with double
quotes), then the Ajax call may fail in the Azure environment.
- Ajax calls are supported only in synchronous mode.