Triggers Form

A Trigger is a stored procedure that runs automatically when a row is inserted, updated, or deleted in a table. In Deacom, triggers serve two purposes:

  1. Notifying Users or User Groups, via email, when changes to a system table are made. Examples include the creation of a new Vendor record or updates made to a product formula
  2. Creation of EDI output files used for EDI exports such as 810 Invoices.

Triggers are very useful for notifying users when changes or updates to important tables have been made in the system.

Once the Edit Trigger form has been completed and saved, the Trigger setup process is complete. The Trigger will run automatically and produce the appropriate output, either EDI files or emails, whenever transactions are run that insert, update, or delete rows in the table indicated on the Edit Trigger form.

Notes:

  • Anytime changes are made to the trigger via the Edit Trigger form, the automation console or service should be stopped and then restarted.
  • Changes to the fields in System Options are immediately available to Triggers without requiring a restart of the automation console or service.

System Navigation

System > Maintenance > Triggers

Edit Trigger form

General tab

Button/Field/Flag

Description

Copy Trigger

Allows the user to copy another Trigger to use as a base to create a new Trigger.

Show Fields

Displays lists of fields and variables that can be used in the Trigger.

Name

Defines the name of the Trigger, which must be unique.

Trigger Event

Pick list used to define when the Trigger will fire. Options are:

  • Both - trigger fires when record is updated or inserted.
  • Insert - trigger fires when a record is inserted in a table.
  • Update - triggers fires when a record is updated in a table.

Table

Pick list used to indicate the Deacom table that will be used as the source of the Trigger.

Output

Pick list used to select the result of the Trigger firing. Options are:

  • EDI - Creates an EDI file.
  • HTTP POST - If selected, Triggers will post to a URL.
  • HTML Email - Sends an email in HTML format.
  • Plain Text Email - Sends an email in plain text format.

Subject

Information or text that will populate the subject line of the email.

  • This field is disabled when selecting a "Output" of "HTTP POST."
  • The system will use the information or text in this field to name any files sent via the "Attachments" tab.

Destination

Address for email or folder for EDI file or, when the "Output" field is set to "HTTP POST," the URL where the trigger will post.

  • Multiple email addresses may be used, separated by semicolons.
  • Only one file path is allowed, and may contain a string of text and field names indicating what the file should be named when it is saved to the folder.
  • When using the "Attachments" tab on this form, this field defines the email or folder address for the attached files.
  • OAuth2 support is available for Trigger Emails. If this field is set to OAuth2 and sending an email using trigger credentials, the system will use OAuth2 to send the trigger email.

CC Email

Address for an email to be sent a carbon copy, which will be present on the recipient's header. Only available when Output is set to "HTML Email" or "Plain Text Email".

BCC Email

Address for an email to be sent a blind carbon copy, which will not be present on the recipient's header. Only available when Output is set to "HTML Email" or "Plain Text Email".

Conditions

Defines the conditions that must be met to fire the Trigger.

  • Only fields in the trigger table are available to the Conditions.
  • Users can use <<>> expressions to add table fields to the message, subject, and destination fields.
  • The "Show Fields" button can be used to determine what fields and variables can be used and any SQL Server functions can be used within the brackets.
  • This field uses T-SQL code and not the traditional Deacom syntax as documented in the "Functions & Operators" library.
  • The expression in the Conditions field must evaluate to a logical TRUE or FALSE, and should be written as if it were to be used in a T-SQL conditional statement, such as CASE WHEN [Conditions Expression] THEN [trigger should fire] ELSE [trigger won't fire] END

Message

Message body for email or contents of EDI file.

  • Utilizes FoxPro functions.
  • The lc_username variable may be used in this field to specify the name of the user that made changes to the specified Table or Condition.
  • When selecting a "Table" of "Sales Order Header" and a "Trigger Event" of "Update", the LOTINFO and MASTERLOTINFO tags can be used in Triggers.
  • The BYTESTOSTRING() function can be used in this field to parse the dxedihistory.eh_msg field from bytes into a larger string.
  • Additional information is available via Deacom Basics > Functions and Operators Library.
  • If the "Output" field is set to "HTTP POST," the Message field will be a JSON string that the user generates. Upon processing the trigger, the fully parsed and executed message field will be converted from JSON to a dictionary and the results of that dictionary will be sent as HTTP POST keys to the URL. If the post is successful (HTTP 200) the text response from the server will be inserted in the trigger history as part of the success entry.

Delivery Expression

Used to enable a delayed action in a Trigger. In other words, it is used to hold the expression to calculate the date and time when a Trigger should fire.

  • Example: DATE() + 2, with the Trigger to set to fire for the update/insert of SO headers.
  • Behind the scenes, the system contains a table, dttrigdel, with the fields listed below.
    • td_tgid = Trigger ID
    • tg_id = ID
    • td_recid = Trigger Record Table
    • td_table = Trigger record table
    • td_delivery = Date/time of scheduled fire
  • The system will check to see if the Trigger has valid delivery expression.
    • If valid, the system adds a record to the dttrigdel table and adds history telling the user the Trigger has been scheduled for the date/time specified.
    • If not valid, the system will add history to the History / Performance report or the View EDI Import History report with a message stating invalid delivery expression.
  • If the delivery date is in the past, fire trigger as normal. A timer has been added to the automation service to fire when restarted and every 30 minutes. Timer will check all Triggers to be delivered and compare them to the current date/time. If the date/time is greater than the delivery date/time, fire the trigger.

Delivery Condition

Designed to handle situations where reminders to a Vendor need to be sent at various times and on various dates.

  • Can be used in connection with the "Delivery Expression" field, which can be set to fire to determine when a Trigger should fire if it is supposed to be delayed. In this case, this field should fire at the actual time that a Trigger is going to be delivered (i.e. the deferred date; For example, 14 days before the "Due To Dock" date (tp_duedock)). This is different than the "Condition" field because "Condition" is a SQL condition for whether the Trigger should even fire at that level and occurs at the time the actual SQL function occurs.
  • This field has all of the same fields available to it as the other fields on the Trigger form.
  • Systematically, the logic of this field is as follows:
    • If the type evaluated is not boolean, fail the Trigger for invalid expression.
    • If expression evaluates to false, note that the Trigger was not executed in trigger history. Otherwise, execute the Trigger.
  • This field uses the traditional Deacom syntax as documented in the "Functions & Operators" library and not T-SQL code. The expression in the Delivery Conditions field must evaluate to a logical TRUE or FALSE, and should be written as if it were to be used in a Deacom conditional statement, such as IIF([Delivery Conditions Expression], [delayed trigger should execute and not write to trigger history], [delayed trigger won't execute, but writes a note to trigger history])

Custom Query

Memo field used to define a custom query that allows greater functionality.

  • Can reference fields just like the "Subject", "Destination", and "Message" fields and any Deacom database fields may be used.
  • Including a field in Custom Query makes that field available to the trigger.
  • Only single lines can be used from the query results and must be selected using the SELECT TOP 1 function to accurately utilize the fields returned.
  • Once the Custom Query is set, the Edit Trigger Message can use fields on the query to return results from the top line of the Custom Query results.
  • This field uses SQL code.

Notes

User can add various notes to the Trigger such as identifying the author or for code explanations.

FTP Server

Only available when selecting an "Output" of "EDI." Defines the address/location of FTP server.

SFTP Port

Port number used for clients who use the Secure File Transfer Protocol. This field will only be used for SFTP and only when it is set to a port number. (greater than 0)

  • Only available when selecting an "Output" of "EDI."

FTP User Name

Only available when selecting an "Output" of "EDI." Defines the unique name of the user for accessing the FTP server.

FTP Password

Only available when selecting an "Output" of "EDI." Defines the unique password of the user for accessing the FTP server.

File Encoding

Pick list that allows users to enable a file encoding type of UTF-8 or Windows Code Page 1252.

  • Only available when the "Output" field is set to "EDI".
  • File encoding of Window Code Page 1252 is particularly useful when dealing with extended characters.

Active

If checked, the Trigger is active and will fire according to the conditions set.

Template

If checked, this record is used as a template to create other Triggers via the "Copy Trigger" button.

  • Triggers flagged as "Template" do not fire.

Add Line Feeds After Line Items

If checked, the system creates a new line in the message for every new line item on a Sales Order.

Accept Invalid Certificates For FTPS

Only available when selecting an "Output" of "EDI." If checked, indicates that system will accept invalid SSL certificates.

  • This functionality is off by default (denying access to hosts with invalid SSL certificates).

SSH Protocol

Only available when selecting an "Output" of "EDI."

  • When checked, Trigger History (System > View Trigger History) will also log FTP connection issues.

Attachments tab

The Attachments tab allows customers to attach and send Grid Layouts, as MS Excel files, or Report Layouts, as PDF files, when using email Triggers. The tab can also be used to place Grid Layouts or Report Layouts in the path specified in the "Destination" field on the form when using an "Output" type of "EDI." Grid Layouts or Report Layouts may be attached to trigger emails when using either the "HTML Email" or "Plain Text Email" option in the "Output" field on the General tab. The name of the MS Excel or PDF file will be the same as the text specified in the "Subject" field. See the Sending attachments and reports using Triggers help section for more information on the process.

Button/Field/Flag

Description

Grid Layout

Search box used to select the Grid Layout that will be attached to the trigger email or placed in the location specified in the "Destination" field on the General tab of this form. The list contains all active Grid Layouts in the system.

  • Disabled when the "Output" field on the General tab is set to "HTTP POST."
  • The "Output" field must be set to "EDI" in order for the Grid Layout to be placed in the Destination location.

Print Out

Search box that displays active Report Layouts based on the entry made in the "Table" field on the General tab. For example, if the Job Header (dtjob) table is selected, only Report Layouts with a type of "Job" will be visible in the list.

  • Only enabled when the Grid Layout field above is not empty.
  • The "Output" field must be set to "EDI" in order for the Grid Layout to be placed in the Destination location.

Export To Excel

If checked, the Grid Layout that is emailed or placed in the Destinations location will be in MS Excel format.

  • Only enabled when the Grid Layout field is not empty.