web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics RMS (Archived)

SQL Trigger DBMail Issue

(0) ShareShare
ReportReport
Posted on by

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)
  • Suggested answer
    Community Member Profile Picture
    on at

    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.  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics RMS (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans