Calling a Synchronous Event within a Transaction and Handling Failure

  1. Determine the current site.
  2. Name a configuration, by convention:
    DECLARE @Site SiteType
    SELECT @Site = site FROM parms
    
  3. Determine the current SessionId:
    DECLARE @SessionId RowPointerType
    SET @SessionId = dbo.SessionIdSp()
  4. Add the procedure code:
    BEGIN TRANSACTION 
    UPDATE coitem
    SET due_date = dbo.CalcDueDate(@Parm1, @Parm2)
    WHERE coitem.co_num = @CoNum
    AND coitem.co_line = @CoLine
    AND coitem.co_release = @CoRelease
    
    SET @MyEventParmId = NEWID()
    EXEC InsertEventInputParameterSp @MyEventParmId, 'CoNum', @CoNum
    EXEC InsertEventInputParameterSp @MyEventParmId, 'CoLine', @CoLine
    EXEC InsertEventInputParameterSp @MyEventParmId, 'CoRelease', @CoRelease
    
    DECLARE
    @anyHandlersFailed [tinyint],
    @result [nvarchar](4000),
    @Infobar [nvarchar](4000)
    
    EXEC @Severity = FireEventSp
    @eventName = SetCoitemDueDate',
    @configName = 'SyteLine',
    @sessionID = @SessionID,
    @eventTrxId = null,
    @eventParmId = @MyEventParmID OUTPUT,
    @transactional = 0,
    @anyHandlersFailed = @anyHandlersFailed output,
    @result = @result output,
    @Infobar = @infobar output
    
    IF @Severity > 0
    BEGIN
    EXEC RaiseError @Infobar, @Severity
    ROLLBACK TRANSACTION END
    ...
    COMMIT TRANSACTION