Using validation functions

To make the transition from older system versions easier, you can use the validation and search functions that run in Administration → Service Console. The functions scan calculations, dynamic conditions, dynamic rows, print templates (Case Overview) and global scripts, look for unsupported code, and can fix some of the findings automatically.

How the functions are called depends on the TAS version:

TAS version

Where the functions live

Call prefix

5.7 (from 5.7.33)

Built into the system

sys.

5.17 – 5.19

Template Validation plugin, version 1.x

validation. (same function names as in 5.7)

From version 5.17, the functions are no longer part of the system core. The Template Validation plugin must be installed and active on the environment, otherwise the validation object does not exist in the Service Console.

Version 5.7 – built-in sys. functions

Available from version 5.7.33.

Finding where global scripts are used in calculations

To find where a specific global script is used in calculations, use the functions below.

sys.findScriptImportstInCalculations();

With an empty first parameter, the function searches all templates on the environment.

sys.findScriptImportstInCalculations(1626);

With a template ID, the function searches and returns tasks from that template only.

From the result, you can click through directly to the specific template or task.

Finding a specific function or text in global scripts

sys.findInScripts('result.data.split');

Finds where result.data.split is used.

You can also use a regular expression:

sys.findInScripts(/\bvar\s+approverArray\s*=\s*JSON\.parse\s*\(/);
Just ask an AI assistant for a RegExp for the sys.findInScripts() function.

Finding a specific function or text in calculations

sys.findInCalculations('sortedTaskActual', 27);

Finds where sortedTaskActual is used in the template with ID 27.

sys.findInCalculations('sortedTaskActual');

Without a template ID, it finds where sortedTaskActual is used in all templates.

You can also use a regular expression:

sys.findInCalculations(/\bvar\s+approverArray\s*=\s*JSON\.parse\s*\(/);
Just ask an AI assistant for a RegExp for the sys.findInCalculations() function.

Finding a specific function or text in dynamic conditions and dynamic rows

sys.findInConditions('test');

Finds where the string test is used in all dynamic conditions and dynamic rows (script).

Finding unsupported functions (lodash and other discontinued functions)

A detailed description of the lodash upgrade can be found here. This check is already available in version 5.3.

sys.validateTemplate(1626);

Scans a specific template and returns all occurrences of unsupported functions. It scans:

  • calculations,
  • dynamic conditions,
  • dynamic rows,
  • print templates.
It also detects broken scripts. To fix them automatically, use the sys.fixTemplateIssues(); function.
sys.validateTemplates();

Scans all templates in the same way as sys.validateTemplate().

sys.validateGlobalScripts();

Checks global scripts (Calculations, CO React, CO).

Automatic replacement of unsupported Lodash functions

sys.replaceDeprecatedLodashUsage();

With an empty parameter, the replacement runs in all templates. With a template ID, it runs in that template only. It replaces code in calculations, dynamic conditions, dynamic rows and scripts. It also automatically rewrites the unsupported _.find syntax (see Lodash Upgrade).

The function writes changes directly to the templates. Export the templates before running it on a production environment.

Versions 5.17 – 5.19 – Template Validation plugin 1.x

The functions have moved to the Template Validation plugin. Their names and parameters are the same as in version 5.7, but they are called through validation. instead of sys., for example:

validation.validateTemplate(1626);
validation.findInCalculations('sortedTaskActual', 27);
validation.replaceDeprecatedLodashUsage();

All functions from version 5.7 work the same way. Plugin 1.x also adds:

Function

Description

validation.findTextInTemplates('text')

Full-text search across all templates.

validation.findTextInTemplate(1626, 'text')

Full-text search in a single template.

validation.findFunctionInTemplates('functionName')

Finds where a specific function is used in all templates.

validation.findFunctionInTemplate(1626, 'functionName')

Finds where a specific function is used in a single template.

validation.findFunctionInScripts('functionName')

Finds where a specific function is used in global scripts.

validation.validateMuiGrid()

From version 5.18.2. Checks all templates and global scripts for deprecated MUI Grid v6 props (xs, sm, md, lg, xl, xsOffset, item, zeroMinWidth).

validation.fixMuiGridProps(1626)

From version 5.18.2. Fixes deprecated MUI Grid props. Without a parameter, it runs in all templates and global scripts.

validation.checkAsyncAwaitRetranspilationNeeded(1626)

From version 5.18.14. Lists calculations and global scripts that need to be retranspiled. Without a parameter, it checks all templates and scripts. To retranspile, use sys.retranspileCalculationsByProcessId() and sys.retranspileGlobalScripts().

Pre-upgrade check – validation.checkMigration()

validation.checkMigration();

Scans the whole system, including global scripts, and returns a summary table of findings grouped by rule. Each rule shows its severity, the number of occurrences, and whether it can be fixed automatically.

validation.checkMigration(1626);

Checks only the template with ID 1626.

Finding severity:

Severity

Meaning

error

Does not work now – the function or API no longer exists in the system.

warning

The code runs, but behaves incorrectly or the data is inconsistent.

deprecated

Still works, but its removal is scheduled. The report shows the version until which it will keep working. After upgrading to that version, the finding automatically changes to error.

info

Cosmetic finding.

Rule detail – validation.checkRule()

The rule ID (ruleId) is shown in the validation.checkMigration() report.

validation.checkRule('lodash.pluck');
validation.checkRule('lodash.pluck', 1626);

Lists every place where the rule fired, with a link to the template, task or script.

Search – validation.find()

Replaces all earlier search functions (findInScripts, findInCalculations, findInConditions, findTextInTemplate(s), findFunctionInTemplate(s), findFunctionInScripts).

validation.find('result.data.split');

Searches for the text in all templates and global scripts.

validation.find('sortedTaskActual', { tProcId: 27 });

Searches for the text only in the template with ID 27.

validation.find(/\bvar\s+approverArray\s*=\s*JSON\.parse\s*\(/);

The search term can also be a regular expression.

Just ask an AI assistant for a RegExp for the validation.find() function.

Optional second parameter options:

Parameter

Description

tProcId

Template ID. Without it, the whole system is searched, including global scripts.

mode

'text' (default) – any occurrence of the text,

'call' – only places where the function is called,

'definition' – only places where the function is defined.

kinds

Limits the search to selected code types: 'taskCalculation' (calculations), 'taskCondition' (dynamic conditions), 'dynamicRow' (dynamic rows), 'caseOverview' (Case Overview), 'globalScript' (global scripts).

caseSensitive

true for a case-sensitive search.

Examples:
validation.find('getApprovers', { mode: 'definition' }); – where the getApprovers function is defined,
validation.find('getApprovers', { mode: 'call', kinds: ['taskCalculation'] }); – where it is called in calculations,
validation.find('test', { kinds: ['taskCondition', 'dynamicRow'] }); – the equivalent of the former findInConditions('test').

Automatic fix – validation.fix()

validation.fix('lodash.find-3arg');
validation.fix('lodash.find-3arg', 1626);

Fixes the findings of the given rule, writes the changes and lists the diff of every change. Only rules that have the fix column filled in the validation.checkMigration() report can be fixed. Each fixable rule shows the confidence of its fix:

  • safe – the fix is safe,
  • review – the fix should be reviewed,
  • bestEffort – the fix is a best guess and the result must be reviewed.

Automatically fixable rules:

Rule

Fix

lodash.find-3arg

Rewrites _.find(coll, 'prop', value) to _.find(coll, { prop: value }). Confidence review.

mui.grid.deprecated-props

Converts deprecated MUI Grid v6 props to the v7 syntax in Case Overview and global scripts. Confidence safe.

data.append-scripts-format

Repairs an incorrectly stored list of imported global scripts in calculations. Confidence safe.

api.proc.iproc-case-status-attribute

Rewrites the use of the IPROC_CASE_STATUS attribute to proc.setCaseStatus() / proc.getCaseStatus(). Confidence review.

The function writes changes directly to templates and scripts. Export the templates before running it on a production environment, and review the result of fixes with the review and bestEffort confidence.

Global scripts used in calculations – validation.findScriptImports()

validation.findScriptImports();
validation.findScriptImports(1626);

Lists which global scripts each task calculation imports. Without a parameter, it covers all templates; with a template ID, only that template.

What the validation checks

  • Unsupported Lodash functions – e.g. _.pluck, _.where, _.findWhere, _.first, _.indexBy, _.pairs, _.padLeft, _.trimLeft, _.sortByOrder and _.find called with three parameters. The report always gives the replacement.
  • Removed API functions:
    • lib.storeCsvFromDms(), lib.getAresData(), lib.setList(),
    • lib.getPublicKey(), lib.getSecret(), lib.setSecret() – replaced by vault.get(),
    • lib.getCertificatePath() and hardcoded paths to the certificate directory – replaced by lib.getCertificate(certName),
    • all curl.* functions – use AxiosApi for REST calls and FtpApi for FTP/SFTP,
    • docx.generate() and docx.docxTemplater() – replaced by docxGenerator.generate(),
    • the POST method for /dms/download/:id and /dms/archived/download/:id – use GET.
  • Deprecated functions – lib.dmsPdfFileToText() (replaced by lib.pdfToText()), IPROC_CASE_STATUS (replaced by proc.setCaseStatus() / proc.getCaseStatus(), or lib.changeCaseStatus() for another case).
  • Public file URLs under /assets/, which are no longer supported.
  • Deprecated MUI Grid v6 props in Case Overview and global scripts.
  • Calculations and global scripts that need retranspiling – retranspile them with sys.retranspileCalculationsByProcessId() or sys.retranspileGlobalScripts().
  • Calculations importing a global script that no longer exists.
  • Invitation tasks – this task type has been removed; these tasks need to be removed or replaced.
  • Historical B variables – this variable type has been removed.

Conversion table from plugin 1.x to 2.x

Original function (5.7 sys. / plugin 1.x validation.)

Plugin 2.x (from 5.20.8)

validateTemplate(tProcId)

validation.checkMigration(tProcId)

validateTemplates(), validateGlobalScripts(), validateMuiGrid(), checkAsyncAwaitRetranspilationNeeded()

validation.checkMigration()

findInScripts(term)

validation.find(term, { kinds: ['globalScript'] })

findInCalculations(term, tProcId)

validation.find(term, { tProcId, kinds: ['taskCalculation'] })

findInConditions(term, tProcId)

validation.find(term, { tProcId, kinds: ['taskCondition', 'dynamicRow'] })

findTextInTemplates(text), findTextInTemplate(tProcId, text)

validation.find(text, { tProcId })

findFunctionInTemplates(name), findFunctionInTemplate(tProcId, name), findFunctionInScripts(name)

validation.find(name, { tProcId, mode: 'call' }) or mode: 'definition'

replaceDeprecatedLodashUsage(tProcId)

validation.fix('lodash.find-3arg', tProcId)

fixMuiGridProps(tProcId)

validation.fix('mui.grid.deprecated-props', tProcId)

fixTemplateIssues(tProcId)

validation.fix('data.append-scripts-format', tProcId)

findScriptImportstInCalculations(tProcId)

validation.findScriptImports(tProcId)

Hints for the current methods are shown directly in the Service Console editor as you type validation.

Frantisek Brych Updated by Frantisek Brych

Best Practices for Upgrading from v4 to v5

Contact

Syca (opens in a new tab)

Powered by HelpDocs (opens in a new tab)