Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Client-side scripts allow the system to run JS scripts in the browser when the client-side events happen, for example:
- form loading;
- form submitting;
- field value changing.
Client-side scripts are used to configure forms, form fields, and field values while the client uses the form. Their abilities:
- make the field hidden or visible;
- make the field read-only;
- make the field mandatory or non-mandatory;
- set the value in one field, basing on the value in another field;
- change parameters in a Choice list;
- show a message basing on the field value.
The client-side script form configuration
The client script can be configured via the SimpleOne administrative interface.
Tip |
---|
Required role: admin. |
To configure a script, please complete the steps below:
- Navigate to System Definition -> Client Script.
- Click New and fill in the fields.
- Click Save or Save and Exit to apply changes.
Client script form fields
Name | Description | ||
---|---|---|---|
Name | Client-side script name. | ||
Table | A table on which form the script will be executed. | ||
Type | The script type:
| ||
Views | Specify a form view on which the client script should be run. You can specify more than one view. If no view is specified, then this client script will be executed on all the views if there are any. | ||
Condition | Specify a trigger condition for this client script that must be met so that the script runs. Use the Condition Builder to build complex AND/OR filters.
| ||
Description | A detailed description of script actions. | ||
Messages | Write a message you want to show to a user when a client script is performed. | ||
Active | When set to TRUE, the script is active; otherwise, it is not. | ||
Inherited | When set to TRUE, the script will be applied not only for the table specified in the Table field but also for all its child tables. | ||
Order | Defines the order of the client script execution. If there are several client scripts, they will be executed in the ascending order. | ||
Script | This field contains a client-side script. |
Client-Side API
In the client-side scripts, you can use methods that are provided by client-side API (SimpleForm class).
Special Features
Use callback functions to work with SimpleRecord objects:
Code Block |
---|
const record = new SimpleRecord('task'); record.get('159644860216948298', () => { console.log(record.number); // TSK0000123 }); |
Dot-walking is not available for fields of the Reference type. You can usecallbackfunction sequence as a workaround.
For example, instead of server-side dot-walking:
Code Block | ||
---|---|---|
| ||
current.slm_commitment.agreement.service_id |
in client-side script it will be looks like:
Code Block |
---|
const commitmentID = s_form.getValue('slm_commitment');
if (commitmentID) {
const commitment = new SimpleRecord('slm_commitment');
commitment.get(commitmentID, () => {
const agreement = new SimpleRecord('agreement');
agreement.get(commitment.agreement, () => {
const service = new SimpleRecord('sys_cmdb_ci_service');
service.get(agreement.service_id, () => {
s_form.setValue('service_id', agreement.service_id, service.name);
});
});
});
} else {
s_form.clearValue('service_id');
} |
Table of Contents | ||||
---|---|---|---|---|
|