You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 62 Next »

Common information


Client scripts are used to execute JS scripts in the browser when the client-side events happen, for example:

  • form loading
  • form submitting
  • field value changing.

Client scripts allow configuring forms, form fields, and field values while the client uses the form. They can execute the following actions:

  • 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.

Client-side scripts are used to execute JavaScript scenarios on the client-side. Client-side scripts may be either a record of the Client Script (sys_script_client) table or it can execute within some UI Actions when its Client parameter is equal to 'true'.


Also, client logic can be implemented within the widget client script:


General client-side classes are: SimpleFormSimpleList, and SimpleUser. To get more information about client-side classes, please check our API reference article.

Creating a client script


The client script can be configured via the SimpleOne agent interface.

Required role: admin.

To configure a script, please complete the steps below:

  1. Navigate to System Definition → Client Script.
  2. Click New and fill in the fields.
  3. Click Save or Save and Exit to apply changes.

Client script form fields

NameMandatoryDescription
NameYClient-side script name.
TableYA table on which form the script will be executed.
TypeY

The script type:

  • onLoad – it starts when the system displays the form for the first time before users enter data. Generally, onLoad scripts perform manipulations on the client-side with the current form or default record values set.
  • onChange – it starts when the specified field in the form is changed.
  • onSubmit – this client-side script can cancel form submission by returning 'false'.
  • onCellEdit – this client-side script starts when some cell is being edited.
    • oldValue – the old value for the cell that is being edited.
    • newValue – the new value for the cell that is being edited.
    • table – the table name of the cell that is being edited (for example, sys_db_table).
    • sysId – the ID of the record relevant to the cell that is being edited.
    • callback – if this variable is equated to 'false', then subsequent scripts will not run; otherwise, they will execute.
ColumnY

A drop-down list. Specify the column, the change or editing of which starts the script.

This field appears when the Type field is onChange, onCellEdit.

ViewsNSpecify a form view, on which the client script should be run. You can specify more than one view. If no view is specified, this client script will be executed on all the views if there are any.
ConditionN

Specify a trigger condition for this client script that must be met to run the script. Use the Condition Builder to build complex AND/OR filters.

Conditions work jointly with values from the Type field. They are applicable only for the onLoad or onChange client-side scripts.

DescriptionNA detailed description of script actions.
ActiveNWhen set to 'true', the script is active; otherwise, it is not.
InheritedNWhen set to 'true', the script will be applied not only to the table specified in the Table field but also for all its child tables.
OrderN

Defines the order of the client script execution. If there are several client scripts, they will be executed in the ascending order.

ScriptNThis field contains a client-side script.

Special Features


Use callback functions to work with SimpleRecord objects:

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 use a callback function sequence as a workaround.
For example, instead of server-side dot-walking:

current.slm_commitment.agreement.service_id

in client-side script it will look like:

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');
}

  • No labels