Examples: Table- and function-based BOD trigger generation
This topic illustrates how to set up BOD generation triggers. This is a task that is part of these other larger procedures:
- Creating requisites for non-transactional replication: Replication Categories step
- Creating and Maintaining BODs: Replication Document Outbound Cross References step
There are two ways to trigger the generation of a BOD using replication categories and replication document outbound cross-references:
- Table-based: The simplest way
is to specify the table or view in the Replication Document
Outbound Cross-References form for the BOD, and then add the table name to
a replication category. Any change made to a record in that table triggers generation of
a BOD. Note: Because they typically exceed MSMQ size limits, columns that contain Binarly Large OBject (BLOB) data are excluded from table-based replication.
If you do not want a BOD to be generated every time anything in that table is changed, you can restrict BOD generation using fields on the Replication Categories form:
- Use the Filter attribute to define a filter that determines if a change to the table must trigger BOD generation. Only records that match the filter are included.
- Use check boxes that restrict BOD generation based on the type of change to the table: Skip Insert, Skip Update and Skip Delete.
- Function-based: Use this
approach when a simple table-based trigger is inadequate.
For example, suppose you want to trigger a BOD when a new order is created. Since an order is hierarchical data and may have any number of lines and releases, it would not be possible to identify a single table that would trigger the BOD generation; there is no way to know when the last line or release has been inserted. Or you may need to trigger BOD generation when some other application event occurs that is completely unrelated to a table update. The solution is to programmatically trigger the BOD update using a "Function" trigger.
In the Replication Categories form and the Replication Document Outbound Cross-References form, you specify a Function name. This name does not necessarily correspond to an actual stored procedure, and likely it will not. It is really just a parameter that is passed into a replication stored procedure that ultimately triggers the BOD generation.
You could also call this stored procedure from a trigger, another stored procedure, or an IDO extension class as well (and probably other contexts, if necessary).
If you plan to generate different XML documents for different target sites, you can include the appropriate target site's Intranet Name on the replication document cross-reference record.
Function Trigger Setup Example
Scenario: Whenever the "function" TriggerSalesOrderSyncSp is invoked by some system action, you want your BOD to be generated.
In the Replication Document Outbound Cross-References form, specify this trigger information:
- Applies to IDO: SP!
- Applies to IDO Action: Invoke
- Applies to Method: TriggerSalesOrderSyncSp
In the Replication Categories form, specify this trigger information:
- Table or Function: TriggerSalesOrderSyncSp
- Object Type: SP
- Filter: Leave this field blank.
Define the rest of the BOD and replication setup as specified in the procedure topics listed above.
Table Trigger Setup Example
Scenario: You want your BOD to be triggered by a change to the employee view on the employee_mst table, according to the filters and check boxes you specify in the Replication Categories form.
In the Replication Document Outbound Cross-References form, specify this trigger information:
- Applies to IDO: TABLE!employee
- Applies to IDO Action: UpdateCollection
- Applies to Method: N/A
In the Replication Categories form, specify this trigger information:
- Table or Function: employee
- Object Type: Table
- Filter: Specify any appropriate filter.
Set the rest of the columns as needed.
Define the rest of the BOD and replication setup as specified in the procedure topics listed above. If you use non-primary key fields from the UpdateCollection (column names) as properties, then you must set the Update All Columns check box in the Replication Rules form. When you add a replication rule for a table, you must regenerate the replication triggers.