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

  1. Go to Platform Services > Objects.
  2. Click the Employee object and at the top of the page, click Triggers.
  3. 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
  4. 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!}.
    
  5. Click Save and click Save again.

Test your trigger

  1. Go to Reports > Setup tab > Dimensions > Employees.
  2. On the line for the employee whose status you need to update, click Edit.
  3. Update the status to Inactive and click Save.
  4. 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

  1. Go to Platform Services > Objects.
  2. Click the Department object and at the top of the page, click Triggers.
  3. 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
  4. 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_'";
     }
    
  5. Verify that your code works using the debug option and click Save.

Test your trigger

  1. Go to Reports > Setup tab > Dimensions > Departments.
  2. On the line for the department whose name you need to update, select Edit.
  3. Update the name so that it doesn’t contain “DEP_” at the start.
  4. 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

  1. Go to Platform Services > Objects.
  2. Click the Employee object and at the top of the page, click Triggers.
  3. 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
  4. In the JavaScript editor, your code might look like the following, where:
    -EMPLOYEE.DEPARTMENTID of “430” corresponds to department “430-Executive” -The return value 3 corresponds to the employee’s location, “110-Downtown”

         if ("{!EMPLOYEE.DEPARTMENTID!}" == "430") {
           return 3;
         } else {
           return {
               !EMPLOYEE.LOCATIONKEY!
           };
         }
    

Test your trigger

  1. Go to Reports > Setup tab > Dimensions > Employees.
  2. Select Edit next to the employee name whose record you want to update.
  3. Update the department to “430–Executive” and click Save. Go back to view the record. Notice that the location is set to “110–Downtown.”

Provide feedback