Using stored procedures in Process Automation
Stored procedures are a set of SQL statements that are stored and executed on the database server. In the context of iMIS, stored procedures (executed by Process automation triggers) update the underlying tables whenever a trigger is executed.
Important! Custom stored procedures are only supported for self-hosted clients.
For example, you want to create a Trigger that updates a table every time a contact’s Paid Through date is updated. In this case, the stored procedure is triggered based on an updated database property.
The workflow for using stored procedures is as follows:
- Setting up the Trigger
- Creating the query and filters
- Defining the Conditions
- Defining the Actions
Setting up the Trigger
Do the following to create the trigger:
- Go to RiSE > Process automation.
- Select Add new task.
- Enter a Name and optional Description.
- Select Add trigger:
- From the Type field, choose On database change.
- Select Name from the Table drop-down.
- From the Trigger on field, enable Row updated and choose Specific column.
- From the Column drop-down, select PAID_THRU.
- Click Save.
The window displays a message stating the TriggerID property is the ID. This property can now be used as a data source in the Actions and Conditions of the scheduled task.
- Click Save & Exit.
Creating the required query and filter
The query is required to have the following configuration:
- The TriggerID property displayed next to the Table drop-down added as a filter.
- The filter value equals "@TriggerID".
- The In search? field set to No in the query filter.
Important! The @TriggerID must be enclosed in double quotes: "@TriggerID"
Without these settings, the trigger will not properly execute.
Do the following to create the source query and filter:
- Go to RiSE > Intelligent Query Architect > New > Query.
- (Summary tab) Enter a Name.
- (Sources tab) Add the NetContactData source.
- (Filters tab) Add the following filters:
- [NetContactData] Id
- Function - None
- Comparison - Equal
- Value - Constant "@TriggerID"
- [NetContactData] Paid Through
- Function - None
- Comparison - Equal
- Value - Dynamic Current Date
- [NetContactData] Id
- Click Save As to save the query to a shared folder.
Now the query can be used as a Condition in the task to further filter the results. If a query is used in the Conditions of a task, the Actions of the task are only performed if the query returns at least one row.
For example, the Conditions can be used to ensure the Actions do not run if the Paid Through date is in the future by making sure the query only returns rows with a Paid Through date in the past.
Additional notes about using the "@TriggerID" in queries
If the table has more than one Trigger property, add multiple filters in the form of:
- "@TriggerId1"
- "@TriggerId2"
For example, Order_Lines has a composite Trigger property of ORDER_NUMBER and LINE_NUMBER.
Reference the trigger properties in the query by adding two filters:
- [CsOrderLines] Order Number = "@TriggerId1"
- [CsOrderLines] Line Number = "@TriggerId2"
Defining the Conditions of the scheduled task
Conditions determine whether the task will be executed or not. Do the following to define the Condition:
- Go to RiSE > Process automation.
- Open the scheduled task for edit.
- From the Conditions tab, select Add data source:
- Enter a Data source name.
- Select the query.
- Click Save.
Note: Spaces are not allowed in the Data source name field.
- Click Save.
Defining the Actions of the scheduled task
The actions are where you define what you want to happen. In this case, the Action must be set to Run a stored procedure. If there is a Trigger defined that has a Trigger ID, the Action will display the Enable TriggerIDs as parameters checkbox.
Do the following to define the Action:
- Go to RiSE > Process automation.
- Open the scheduled task for edit.
- From the Actions tab, select Add action:
- From the Type drop-down, choose Run a stored procedure.
- Enter a Stored procedure name.
- Enable the Enable TriggerIDs as parameters option.
- Click Save.
- Be sure to enable the scheduled task.
- Click Save & Exit.
Now, anytime the Paid Through date is updated for a contact, the stored procedure updates the associated table.