Trigger Examples
- Use an Email trigger type to send an email about employee deactivations
- Use a Validation trigger type to ensure accurate naming
- Use an Update Field Value trigger type to update a field value when a record is created or updated
- Use an API trigger type to add a record to another object
Triggers offer powerful options for automating common tasks. Based on your specific use case, you can use one of several trigger types. Use the examples in this topic as starting points to create your own triggers.
Use an Email trigger type to send an email about employee deactivations
The Send Email trigger type sends an email to the recipient whom you specify based on an action that triggers the email. For example, your 10-person startup might be competing for talent in a competitive environment. Your founder wants to know when employees leave your company.
Create your trigger
- Go to Platform Services > Objects.
- Click the Employee object and at the top of the page, click Triggers.
-
Click New Trigger and define it with the following attributes.
Trigger Type Send Email This trigger is deployed Select (true) Trigger Activation Before Update Trigger Name Employee Deactivation Email On Field Change Status Use Field Leave Blank Send to Enter an email address Reply to Enter an email address -
Click + next to Email Template to create a new template. We’re using “Employee Status Change Email.” Your template body might look something like the following:
{!EMPLOYEE.PERSONALINFO.FIRSTNAME!} {!EMPLOYEE.PERSONALINFO.LASTNAME!} has left the company as of {!EMPLOYEE.WHENMODIFIED!}.
- Click Save and click Save again.
Test your trigger
- Go to Reports > Setup tab > Dimensions > Employees.
- On the line for the employee whose status you need to update, click Edit.
- Update the status to Inactive and click Save.
- Check the email box used for the email notification.
Use a Validation trigger type to ensure accurate naming
Use the validation trigger type to set rules about a particular field value. Then test the input value before storing it in the database. Perhaps your organization has guidelines about department names in your new division. You could create a trigger that returns an error if the department name doesn’t comply with the naming guidelines.
Create your trigger
- Go to Platform Services > Objects.
- Click the Department object and at the top of the page, click Triggers.
-
Click New Trigger and define it with the following attributes.
Trigger Type Validation This trigger is deployed Select (true) Trigger Activation Before Create, Before Update Trigger Name Department Name Validation: Division 1 On Field Change Any Update -
In the JavaScript editor, you could add the following code, where if the department title entered does not begin with
DEP_
, then an error displays that reads, “Name must begin with ‘DEP_’”if ("{!DEPARTMENT.TITLE!}".indexOf("dep")==-1) { return "Name must begin with 'DEP_'"; }
- Verify that your code works using the debug option and click Save.
Test your trigger
- Go to Reports > Setup tab > Dimensions > Departments.
- On the line for the department whose name you need to update, select Edit.
- Update the name so that it doesn’t contain “DEP_” at the start.
- You should receive an error message: “Name must being with ‘DEP_’.”
Use an Update Field Value trigger type to update a field value when a record is created or updated
The update field value type can calculate the value to enter in a field that you specify. For example, your company might have multiple offices. When an employee’s position falls into a specified category, their default office location gets updated.
Create your trigger
- Go to Platform Services > Objects.
- Click the Employee object and at the top of the page, click Triggers.
-
Click New Trigger and define it with the following attributes.
Trigger Type Update Field Value This trigger is deployed Select (true) Trigger Activation Before Create, Before Update Trigger Name Employee Dept Loc On Field Change Any Update Record Employee Field to Change LOCATION_KEY -
In the JavaScript editor, your code might look like the following, where:
-EMPLOYEE.DEPARTMENTID
of “430” corresponds to department “430-Executive” -The return value3
corresponds to the employee’s location, “110-Downtown”if ("{!EMPLOYEE.DEPARTMENTID!}" == "430") { return 3; } else { return { !EMPLOYEE.LOCATIONKEY! }; }
Test your trigger
- Go to Reports > Setup tab > Dimensions > Employees.
- Select Edit next to the employee name whose record you want to update.
- Update the department to “430–Executive” and click Save. Go back to view the record. Note that the location is set to “110–Downtown.”
Use an API trigger type to add a record to another object
The Intacct API trigger type fires an API call that you specify to peform an action. For example, let’s say that when you create a new department record in your company, you want an associated Location name created for it at the same time. You can do so using the API trigger type.
Create your trigger
- Go to Platform Services > Objects.
- Click the Department object and at the top of the page, click Triggers.
-
Click New Trigger and define it with the following attributes.
Trigger Type Intacct API This trigger is deployed Select (true) Trigger Activation After Create Trigger Name Create Department Location On Field Change Any Update - Click + next to Document Template to create a new template and name it Create New Department Location.
-
For Template Type, select Generic. Your template body might look something like the following:
<create> <location> <LOCATIONID>{!DEPARTMENT.DEPARTMENTID#text!}</LOCATIONID> <NAME>LOC_{!DEPARTMENT.TITLE!}</NAME> <PARENTID>E200</PARENTID> </location> </create>
- Click Save and click Save again.
Test your trigger
- Go to Company > Setup and click + next to Departments.
- Add an ID for the department that you want to create.
- Add a department name and click Save.
- Go to Company > Locations. You should see a new location listed that has the same ID as that of the deparment you just created. The location name should be the same as the deparment you just created but prepended with “LOC_”. When you’re ready, you can populate the remainder of the location record.