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
Section titled “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
Section titled “Add a Transformation”- Go to Data → Employee Fields in the left-hand menu.
- Find the field you want to transform in the list.
- Click the three dots menu at the end of the row.
- Select Add transformation.
- In the editor, write your JavaScript function using the provided employee and history arguments.
- (Optional) Click Test to run your code and see the output.
- Click Save to activate the transformation.
Example: Calculate Years of Service
Section titled “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.
- 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.
