
Hi,
Can anyone help me set up our RMS version 2.0.2000 so that when a sale happens over a certain amount, it sends an email? I did get the emails to send, but it started messing with the transaction numbers (setting them to small numbers such as '1', '2', '3', and '4') and I can't figure out why. I'll enter the code I used to create the trigger below.
Thanks!
UPDATE:
So after some digging, I found that the Transaction Numbers in the Transaction table are being generated correctly, but related fields in TransactionEntry.TransactionNumber, Journal.ReferenceID, and TenderEntry.TransactionNumber are the numbers being incorrectly generated when the "if" condition is met and the stored procedure msdb.dbo.sp_send_dbmail is called. Anyone have any guesses?
Thanks!
IF OBJECT_ID ('SaleNotify') IS NOT NULL
DROP TRIGGER SaleNotify
GO
CREATE TRIGGER SaleNotify ON [Transaction]
AFTER INSERT AS
BEGIN
SET NOCOUNT ON
DECLARE @total money
DECLARE @tsalestax money
SELECT @total = Total FROM inserted
SELECT @tsalestax = SalesTax FROM inserted
IF(@total >= 2000.00)
BEGIN
declare @body1 varchar(max)
set @body1 = '[Store] has made a sale in the amount of $' + CAST((@total - @tsalestax) as varchar(max))
EXEC msdb.dbo.sp_send_dbmail @recipients='[emails]',
@subject = 'Sale Made - [Store]',
@body = @body1,
@body_format = 'HTML' ;
END
END
*This post is locked for comments
I have the same question (0)You are interrupting the code that RMS uses to link tables together and you should never do that, since your trigger could possibly fail for some reason.
How about instead, you store the values in another table, then have an agent job that sends you the email, then deletes the entries in that table.