AI and Code Checking in Editors

As of version 5.21, every editor in which a consultant writes code has the same buttons below it: Check code and Format. On an installation with AI enabled, an administrator also sees the Ask AI button, which opens an AI chat connected to that specific editor. The AI then writes, modifies or explains the code and always shows you the change for comparison first. This article describes both features using a task calculation as the example. They work the same way in the other editors.

Where to find the buttons

EditorWhere to open it
Task calculationsTemplate → task → Calculations tab, below each calculation section.
Global scriptsAdministration → Scripts: calculation scripts, Case Overview scripts and React scripts.
Service ConsoleAdministration → Service Console.
Authentication method scriptAdministration → Authentication → method detail.
Dynamic conditionsTask dynamic conditions window: the script tab and the script block in the condition builder.
Dynamic rows and dynamic itemsDetail of a variable of the given type, script section.
PrintsTemplate → Print: standard (HTML) print, React print and custom script in the print builder.

Check code

The check runs on the server, so the editor and the server agree on what is wrong in the code. The code is not executed and nothing is saved during the check.

  1. Click Check code. While the check is running, the button reads “Checking…”.
  2. If the code is fine, a No issues badge appears with the message “The code compiles, lint reports no issues and all asynchronous calls are awaited.”
  3. If the check finds something, a badge with the number of issues appears (“1 to review”), the problem spots are underlined in the editor and a list is shown below the editor. Each item contains the issue text, the line and column, and the rule identifier. Click an item to jump to its line.
What the check reportsExample
Syntax errors (in red)A missing bracket, a typo in a keyword. Such code cannot be compiled and will not run.
Missing await (rule calculation/missing-await)vars['Reimbursement'].setValue(...) without await. Without it, the variable may receive an unfinished operation instead of the result. See the article How and when calculations run.
Incorrect use of the result of an asynchronous call (calculation/promise-misuse)dt.from('Rates').get(): a method is called on the result of dt.from before it is available.
Type errors (calculation/type-error)A method or property that the calculation interface does not have, for example the assignment proc.IPROC_DESCRIPTION = … instead of await proc.setAttribute(…).
Linter findingsStyle recommendations and suspicious code, for example let for a variable that never changes (lint/style/useConst), or comparison with == instead of === (lint/suspicious/noDoubleEquals). These are the same rules the TAS developers use.

Format

The Format button normalizes indentation, spacing and line breaks according to a consistent style and puts the result back into the editor. You must save it yourself. If the code is already formatted, TAS reports “The code is already formatted.” Code that cannot be parsed because of a syntax error is left unchanged. Text inside multi-line strings (template literals) is not changed.


Ask AI

The Ask AI button opens an AI chat connected to the editor. The AI knows what code it is dealing with, when it runs and what it should return, and it reads whatever it needs for the job on its own: for a calculation, the template variables and the task’s other calculations; for a print, its content; for dynamic conditions, the form fields; for a dynamic table, its columns; for a shared script, whatever depends on it. The AI checks the proposed code itself before handing it over.

Who sees the button
A user with the $Administrator role (or a superadministrator) on an installation that has AI enabled. The button is only shown for a saved object: for example, a task calculation that already has an ID.
The AI only sees saved code
The AI reads the code from the database, not from the editor. Before you ask, click Save; otherwise the AI works with an older version of the code.

How to have the AI modify code

  1. Save the task (template, script, print).
  2. Below the editor, click Ask AI. The AI chat opens. The header shows the editor badge (for a calculation, for example, Calculation box 1) and the prompt field is prefilled with “Modify this code so that…”.
  3. Complete the sentence, for example “…it waits for the value to be saved and rounds the result to two decimal places”, and send it.
  4. When the AI has prepared the code, the Review generated code window opens.
  5. Go through the differences and click Use generated code. The code is inserted into the editor.
  6. Click Check code and then Save.
Window elementPurpose
NotesText below the heading: what the AI changed and what to watch out for.
CurrentThe code currently in the editor. Removed parts are shown in red.
GeneratedThe proposed code. Added parts are shown in green.
Use generated codeReplaces the editor content with the proposed code. Nothing is saved yet.
CancelCloses the window; the code in the editor does not change.

The conversation continues, so you write the next change as a follow-up message (“also handle the case where the supplier is missing”). Each change again arrives as a proposal for comparison. The AI never writes anything to the database on its own.

Explaining existing code

In the same chat you can ask about the code, for example “Explain what this calculation does and when it runs”. The AI answers in the chat: it describes what the code reads and where it writes, shows an example calculation and tells you at which trigger point it runs. The code in the editor does not change.

Connecting the chat to the editor

As long as the editor badge is shown in the chat header, the chat works with that editor. The Builder mode cannot be selected during that time. Remove the badge with the cross; the chat then works as a regular AI chat.

Always verify the AI’s output
The AI can make mistakes. Read the proposed code, check it with the Check code button and test it on a test case.

TypeScript in calculations

As of version 5.21, calculations, global calculation scripts and the Service Console use TypeScript. The editor suggests the actual names and parameters of the calculation interface methods. You do not have to write type annotations; plain JavaScript is valid TypeScript. TAS no longer adds await for you: you must mark every asynchronous call yourself. What this means in practice is described in the article How and when calculations run.

Dynamic items

In the table designer of a Dynamic Items variable, the toolbar above the column list also contains an Ask AI button. The chat opens with the text “Modify this table so that…” and the AI proposes a change to the columns and table settings, which you again compare and confirm first. For details, see the article on the Dynamic Items variable. The dynamic items script has the Check code, Format and Ask AI buttons like the other editors.

Related: Task calculations; How and when calculations run; Global scripts and React scripts; AI chat; Creating a template: manually, with AI Builder, by import or from a diagram.

Global Scripts and React Scripts

Syca (opens in a new tab)

Powered by HelpDocs (opens in a new tab)