Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
A choice field provides several predefined options to choose from. Only , and only one option can be selected.
In the SimpleOne interface, choice fields are displayed in two ways:
Section | ||||
---|---|---|---|---|
|
Create a choice field
This column database value can contain all kinds of symbols. If the string length is not set, then it is limited to 80 symbols.To create
When creating a
choiceChoice column,
complete the following steps:- Navigate to the System Definition → All Tables.
- Open the table for which you want to create a column.
- Scroll down to the Related Lists area and click on the Columns tab.
- Click New and fill in the fields.
- Click Save or Save and Exit to apply changes.
You can also open the form this way:
- Navigate to System Definition → All Columns.
- Click New, and fill in the fields.
- Click Save or Save and Exit to apply changes.
in addition to the mandatory fields, you need to fill in the
Table field manually.following fields:
Field | Mandatory | Description |
---|
Specify a column type: Choice.
A system column name. It is preferred to be human-readable and keep the kind of stored data. Latin letters, [0..9] numbers, and the underscore symbol ( _ ) are allowed.
Select this checkbox, and customizing of this field displayed on the form and list will be possible.
If unselected, then such a field will be not available for choosing in Form Layout or List layout.
Column type | Y | Specify the |
Choice column type. |
Mandatory | N | Select this checkbox to make the field mandatory ( |
applicable for Choice columns with Choice |
type = Dropdown with -- None --). |
Select this checkbox to display the column's value in record titles and references.
Select this checkbox to forbid creating records with equal values in this field. If a record with value X already exists, there is no way to add a record with this value.
Type Specification tab | ||
Choice table | N | Specify a table that has a column with choice options. |
Choice field | Y | Specify a particular column of the Choice table that contains choice options. |
Choice type | Y | Define whether the option |
None |
is applicable for the field. Available options:
If the Dropdown without --None-- is |
selected, |
the Default Value tab becomes mandatory. |
Extra attributes | N | Enter the text below to apply the radio |
button style to the choice field:
| |||||||
Default Value tab | |||||||
Default |
value | N | The value of a choice option to be populated |
automatically by default. Check the value of a field in the Choice |
options (sys_choice) table. The field is mandatory if the Choice |
type is Dropdown without --None-- (specify a default value). |
Use |
dynamic default | N | Select this checkbox |
if you need the value to generate dynamically. | ||
Dynamic default | N | Select the script from the Dynamic Default Values (sys_default_value_dynamic) |
table, so its execution result will be automatically calculated and entered into this field. This value will be the default value for the column specified. This field appears only when the Use |
dynamic default checkbox is selected.
|
|
|
|
Sources for choice options
There are three ways to define a set of choices for the drop-down lists:
- by inheriting values from a parent table (if the current table is a child to of another one);.
- by creating a set of records for this field in the Choice Options dictionary (sys_choice) ;table.
- by defining a source table and its column in column in the Type Specification tab.
In the second case, you may need to create a different set of choices if the column is inherited and has predefined options. See Overriding of choice options set for child tableColumn Override to learn more.
In the third case, the available options are taken from a particular column of a source table. In the example below, the choice table Role contains a column Name and some records where Name is not empty. The choice options will be values of the Name column in this table.
Create a choice option
Note |
---|
Before creating a set of options for a particular table and column, please make sure that this column is already created (navigate to System Definition → Settings → All Columns). |
To create a choice option for a column table, perform the following steps:
- Navigate to the choice column, for which you need to create a set of options.
- Scroll down to In the Related Lists area and click on the , select the Choice tab.
- Click New, and and fill in the fields.
- Click Save or Save and Exit to exit to apply the changes.
Info |
---|
You can also open the form this the following way:
Please note Note that in this case, you will need to fill in the Table and Column fields manually. |
Choice option form fields
Field | Mandatory | Description |
---|---|---|
Table | Y | Specify the table to which this choice option is related. Select the same table for the translated choice version as for the original one. |
Column | Y | Specify the column to which this choice option is related. Select the same column for the translated choice version as for the original one. |
Title | Y | Type the translation title of the source field thereoption. |
Language | Y | Specify the two-symbol name of the language (ru, en, and and so on). Generally, references to languages are stored in the Languages (sys_language) table. |
Value | Y | Type Specify the same value as specified for the source fieldof the option. |
Order | Y | Enter the number to define the option order in the choice list (options are arranged in the . Options are arranged in ascending order). |
Tip |
---|
An easier A quick way to quickly create several options for the same column is to use Make a copy:
You can also use this way to create a translation for the choice options:
Please note that the Value field has to remain unchanged. |
Overriding of choice options set for child table
Override allows changing choice options set for the child tables extended from the base table. For example, the parent table has the following options for a choice column State: New, Rejected, Processed. An overriding can change the quantity of these options or the options themselves in the child table. For example, for the State new set can be Draft, New, Assigned, Completed, Rejected
|
When creating a choice field option, it is recommended to set text values in the the Value field to increase code readability. For example, it can be incoming, or active, or failed values for Incoming, Active, and Failed choice options, respectively.
Regarding As for task states, it makes sense to make values numericalnumeric; this can help with selection construction (see the code sample below).
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
task.addQuery('state', '>', '2'); // all states after In Progress |
To create a new options set, perform the following steps:
- Navigate to the column for which you want to create a new set.
- Scroll down to the Related Lists area and choose the Choice tab.
- Click New and fill in the fields.
- Fill in the Table field with the name of the table for which you need to configure a new options set.
- Click Save or Save and Exit to apply changes.
Info |
---|
You also can find the form this way:
Please note that in this case, you will need to fill in the Task and Column fields manually. |
To learn how to change the column attributes, please see the Column Overriding article.
Choice list translation
You can provide a set of options for a choice field with localization, which will be displayed in user locale.
To localize a choice list, please complete the steps below:
- Navigate to System Definition → Choice Options.
- Click New and fill in the fields.
- Make sure the Value fields of an option in both languages are equal.
- Click Save or Save and Exit to apply changes.
- Repeat steps 2 – 4 for the rest of the options on the list.
An easier way to quickly localize a set of options for the same column is to use Make a copy.
in code.
Choice list translation
To create a translation for the choice options, complete the following steps:
- Navigate to System Settings → Choice Options.
- Open the option for which you need to create a translation.
- Enter the translation in the Title field and specify the language in the Language field.
- Click Make a copy. A
- copy of the current choice option for the specified language will be created and saved.
Note |
---|
Note that the Value field has to remain unchanged. |
Image Modified
Image Modified
Tipinfo |
---|
If some of the choice options are not localized (for example, some added choice options in English but did not add translations), then in user locale other than English, , the choice lists containing untranslated options will display them in English by default, regardless of the current user locale. To avoid this, please be careful when adding options to your choice lists. |
Peculiarities of choice option values
Choice option values have some peculiarities when displayed within:
Server-Side Script peculiarities
If choice option values are float or integer numbers, you can use an argument as a string or a number:
Code Block | ||||
---|---|---|---|---|
| ||||
const record = new SimpleRecord('field_type_example');
record.get('c_type', '1.5');
// OR record.get('c_type', 1.5);
ss.info(record.sys_id);
ss.info(typeof record.c_type);
// Info: 164027421215882293
// Info: number |
Code Block | ||||
---|---|---|---|---|
| ||||
const record = new SimpleRecord('field_type_example');
record.addQuery('c_type', '1.5');
// OR record.addQuery('c_type', 1.5);
record.query();
record.next();
ss.info(record.sys_id);
ss.info(typeof record.c_type);
// Info: 164027421215882293
// Info: number |
If choice option values are number or string type, values in a choice field will be of the same type:
Code Block | ||
---|---|---|
| ||
const record = new SimpleRecord('field_type_example');
record.get('c_type', '1.5');
ss.info(record.sys_id);
ss.info(typeof record.c_type);
ss.info(typeof record.getValue('c_type'));
// Info: 164027421215882293
// Info: number
// Info: number |
Client Script peculiarities
Regardless of the type of choice option values, in client scripts, values returned by the s_form.getValue() and window.currentCell.value methods will contain the string:
Code Block | ||
---|---|---|
| ||
console.log(typeof s_form.getValue('state'));
// string |
Code Block | ||
---|---|---|
| ||
console.log(window.currentCell)
// {attribute: 'state', value: '-2', tableName: 'itsm_incident', fieldName: undefined, tableId: '156950677111866258', …}
console.log(typeof window.currentCell . value) // 'string' |
When comparing values in a choice field, they should be the same type. If they are not, use loose equality (==):
Code Block |
---|
if (String(current.state) === '-2') {...}
// OR
if (current.state == '-2') {...} |
To check values in a choice field for equality to one of the values, use the following construction:
Code Block |
---|
if ([-2, 0, 2].includes(+current.state)) {...}
// OR
if (['-2','0','2'].includes(String(current.state))) {...} |
Table of Contents | ||
---|---|---|
|