Skip to content

Row type scripts ​

A row type script is a formula for one row type. Each time Salaxy recalculates a calculation, it runs the formula for each row of that type and puts the result in the row. This is the most common way to add a customer's own pay rules. For the big picture, see Custom payroll logic.

Beta

In production, scripts run only for customers that Salaxy has turned the feature on for. See Custom payroll logic.

How Salaxy finds the formula ​

  1. Salaxy goes through the rows of the calculation.
  2. For each row, it takes the row type name:
    • a built-in row type is the rowType of the row, for example hourlySalary (the list is on Wage types);
    • a custom row type is the last part of the row's type: for /custom/eveningBonus it is eveningBonus.
  3. It looks for a class with the same name in the scripts, ignoring case: HourlySalary for hourlySalary. The class must be listed in the metadata with the interface rowTypeScripts.
  4. It calls each method that the metadata lists, and writes the result to the row property of the same name. For example, price() sets the row's price.

A method that returns undefined keeps the value that the row already has.

The methods ​

All methods are optional. Each gets (row, ctx, sxy): the row, the context and the helpers.

MethodSets
priceThe unit price.
countThe count, for example hours.
messageThe row text on the salary slip.
unitThe unit, for example hours or days.
dataThe row type's own data object.
kinddata.kind, the sub-type of the row type.
period, periodStart, periodEnd, periodDaysCount, periodDaysThe row's own period, when it differs from the calculation's period.
accounting, dimensionsAccounting data and cost accounting dimensions, such as the cost centre.
vatPercent, vatEntriesVAT for expense rows.
sourceIdYour own identifier for the row; Salaxy passes it on.
isDeletedtrue removes the row from the result.

Examples ​

A one-line formula: the price of an overtime row is half the hourly salary of the employment.

js
class Overtime {
  price(row, ctx, sxy) {
    return sxy.prices.employment("hourlySalary") * 0.5;
  }
}

A longer rule: the overtime price uses the average hourly pay of the last quarter, or the hourly salary if it is higher, and writes it into the row's data so that the user interface can show it.

js
class Overtime {
  data(row, ctx, sxy) {
    const price = sxy.prices.averageHourlyPay(0.5, "lastQuartal");
    if (row.data?.compensationRows?.length) {
      row.data.compensationRows[0].price = price;
    }
    return row.data;
  }
}

The metadata for both classes is { "interface": "rowTypeScripts", "class": "Overtime", "methods": ["price"] } (or ["data"]). See Where the scripts are stored.

Validation ​

A script can add errors or warnings to ctx.validation. Use this when the business rule finds something wrong, for example a missing price in the employment. The user sees the message with the calculation.

Every page is also available as Markdown: add .md to its URL — a folder page such as white-label/ is white-label/index.md. Index for LLMs: llms.txt. Questions: Support.