Using Great Plains here and one of our users keeps screwing up customer data so we want to put a trigger on the customer table and so we can find out who it is.
Anyway, I created a table called audit_RM00101 as follows:
DATE nchar(10)
CUSTNMBR char(15)
CUSTNAME char(65)
UPSZONE char(3)
SALSTERR char(15)
USERID nchar(100)
I want to capture those same fields from the table I want to audit so I wrote the trigger as follows:
CREATE TRIGGER CatchCustomerRegionUpdate
ON RM00101
FOR UPDATE
AS
DECLARE @UserID VARCHAR(128)
SELECT @UserID = system_user
INSERT INTO audit_RM00101
SELECT DATE, CUSTNMBR, CUSTNAME, UPSZONE, SALSTERR, @UserID FROM UPDATED
The trigger gets created just fine but when I try to test it by updating a customer record in Great Plains, Great Plains throws up an ugly error and the trigger doesn’t get fired.
What am I doing wrong here?
Thanks.
in a trigger, you get the
DELETEDandINSERTEDtables, there is noUPDATED, so replaceFROM UPDATEDwithFROM INSERTEDalso try to fix your USERID column, your
audit_RM00101.USERIDis anchar(100)while@UserIDis aVARCHAR(128).EDIT based on OPs comment: Ah, so there is no way to audit when a table is updated by using a trigger?
DELETEDis populated, butINSERTEDis emptyDELETEDis populated with the original value, andINSERTEDis populated with the newly updated valuesDELETEDis empty, butINSERTEDhas the newly inserted values