Add Employee Field Transformation

A transformation automatically updates an employee field’s value based on a JavaScript function you define. This is useful for deriving values, formatting data, or calculating results from other employee information.


How Transformations Work

  • A transformation runs every time any employee information changes.

  • It receives two arguments:

    • employee – The current employee object with all field values.

    • history – Historical values for the employee’s fields.

  • You can use Lodash functions directly, e.g. sortBy(...).

  • You can also use date-fns for date operations.

  • The function should return:

    • null to clear the field value.

    • The new value to set for the field.


Add a Transformation

  1. Go to Data → Employee Fields in the left-hand menu.

  2. Find the field you want to transform in the list.

  3. Click the three dots menu at the end of the row.

  4. Select Add transformation.

  5. In the editor, write your JavaScript function using the provided employee and history arguments.

  6. (Optional) Click Test to run your code and see the output.

  7. Click Save to activate the transformation.


Example: Calculate Years of Service

function transform(employee) {
  const startDate = employee["startdate"];
  if (!startDate) return null;
  const years = differenceInYears(new Date(), new Date(startDate))
  return years?.toString() ?? null;
}

This transformation:

  • Reads the employee’s startdate field.

  • Uses differenceInYears from date-fns to calculate how many full years have passed.

  • Stores the result as a string in the field.


Tips

  • Keep transformations small and focused for easier debugging.

  • Always handle cases where source data may be missing.

  • Test before saving to ensure the logic behaves as expected.

  • Remember: transformations affect this specific field only.

Last updated

Was this helpful?