Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Tip

Role required: admin.

To debug a script, you can use a built-in debugger

...

Tip

Role required: admin.

For debugging use only the system instances intended for developing and testing business solutions, where there is no sensitive data, to avoid its loss or corruption.

You can use the try... catch blocks for script debugging.

Note

Before debugging, pay attention to the methods:

Escape these methods or remove them to prevent data corruption or loss.

To debug a script, do the following

...

:

  1. Navigate to System

...

  1. Settings → Server Scripts.
  2. Click New and fill in the fields.
  3. Click Save or Save and Exit to save the script, or click Run to execute it without saving.

...

You can also open any record form in this debugger by calling the Open in script item in the hamburger menu.

Using this functionality, you

...

can:

  • locate breakpoints within the script body

...

  • comment some strings to skip one or more operations

...

  • display the object value before inserting or updating

...

  • display the variable value when executing.

It is recommended to use SimpleSystem methods to display values when debugging a server-side script:

  1. To display them on a client-side:
    1. ss.addInfoMessage(message)
    2. ss.addErrorMessage(message)
  2. To put them into the Main Log (sys_log) dictionary, which is intended as the main log storage:
    1. ss.info(message)
    2. ss.warning(message)
    3. ss.debug(message)
    4. ss.error(message

...

Recommendations

To speed up the sampling generation, it is recommended to use the selectAttributes() method of the SimpleRecord class.

The example below generates an array containing IDs of the records:

Code Block
languagejs
themeEclipse
const user = new SimpleRecord('user');
user.addQuery('email', 'like', 'best.company');
user.getAttributes('sys_id'); // выбираем только sys_id
user.query();
const userIDs = [];
while (user.next()) {
  userIDs.push(user.sys_id);
}

Comment your code when you use the Choice attributes in your scripts:

Code Block
languagejs
themeEclipse
if (current.stage == '4' || current.stage == '6') { //Canceled OR Completed
  const start = new SimpleDateTime(current.start_time);
  //...

Use the getAttributes() method to check an object before inserting or updating:

...

languagejs
themeEclipse

...

...

Also, this method allows checking whether an object has a specified attribute or not before calling:

...

languagejs
themeEclipse

...