ctwilliams
Programmer
I am trying to write a trigger that will fire whenever a Sales Entry batch is posted. The trigger will execute a stored procedure, which will perform some tasks in the SOP30200 table to the invoices/returns that were posted.
However, I am having trouble determining what conditions to make the trigger fire on. I have run some SQL Profiler traces and it appears that when a batch is posted, it is sometimes deleted from the SY00500 table, but other times the BCHSTTUS and MKDTOPST fields are updated and the record is left in the table. The record appears to always be deleted from the SY00800 table in DYNAMICS, but I am afraid to put a trigger on this table since it affects so many other processes.
Here is my trigger:
Here is the code (obtained from Profiler) that is being executed to delete the batch record from the SY00800 table:
However, I am having trouble determining what conditions to make the trigger fire on. I have run some SQL Profiler traces and it appears that when a batch is posted, it is sometimes deleted from the SY00500 table, but other times the BCHSTTUS and MKDTOPST fields are updated and the record is left in the table. The record appears to always be deleted from the SY00800 table in DYNAMICS, but I am afraid to put a trigger on this table since it affects so many other processes.
Here is my trigger:
Code:
CREATE TRIGGER [MyTrigger] ON SY00500 FOR DELETE AS
IF EXISTS (SELECT * FROM deleted WHERE BCHSOURC = 'Sales Entry')
BEGIN
DECLARE @BACHNUMB varchar(15)
SELECT @BACHNUMB = BACHNUMB FROM deleted
EXEC MyStoredProc @BACHNUMB
END
Here is the code (obtained from Profiler) that is being executed to delete the batch record from the SY00800 table:
Code:
DELETE FROM DYNAMICS.dbo.SY00800
WHERE WINTYPE = 2 AND USERID = 'XXXX'
AND CMPNYNAM = 'XXXX' AND BCHSOURC = 'Sales Entry'
AND BACHNUMB = 'XXXX'
and (not exists (select 1 from tempdb.dbo.DEX_LOCK where row_id = 1196696 and table_path_name = 'DYNAMICS.dbo.SY00800')