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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

SOP Trigger

(0) ShareShare
ReportReport
Posted on by

Hello

The purpose of my trigger is :
When someone creates Order , an automatic email generate to inform certain person for the creation , with the details SOPnumber , Customer , shipping method and slaespersonne
The problems :
1 - When someone just click on SOPNUMBE , which generates a new SOPNUMBE it sends an email .2 - If two user typing an order at the same time , for example ( 23000 and 23001 ), one of both remove the order ( 23000 ) , if another user wants to enter a new order the sequence number does not take ( 23000 ), which is free, starts at ( 23002 ) . 3 - retrieve information ( SOPNUMBE , CSTPONBR ... ) in sending the e-mail are all empty except SOPNUMBE ,

 can someone help me. 

Create Trigger [dbo].[SOP_Order_New]

ON [dbo].[SOP10100]

After Insert

As

Begin

set nocount on;

DECLARE @SOPNUMBE  AS char(21)

DECLARE @CSTPONBR  AS char(21)

DECLARE @SHIPMTHD  As char(15)

DECLARE @SLPRSNID  As char(15)

DECLARE @Message   AS Varchar(max)

DECLARE @Xml       As varchar(max)

 

Set @SOPNUMBE = (select SOPNUMBE from inserted where SOPTYPE=2)

Set @CSTPONBR = (select CSTPONBR from inserted where SOPTYPE=2)

Set @SHIPMTHD = (select SHIPMTHD from inserted where SOPTYPE=2)

Set @SLPRSNID = (select SLPRSNID from inserted where SOPTYPE=2)

Set @Xml=

CAST(( select

@SOPNUMBE As 'td','',

@CSTPONBR As 'td','',

@SHIPMTHD As 'td','',

@SLPRSNID As 'td'

from inserted 

For XML Path ('tr'),ELEMENTS ) AS nvarchar(Max)) 

if @SOPNUMBE <>'' 

begin 

Set @Message='<html><body><H3>New Order Info</H3>

<table border = 1>

<tr>

<th>Document Number </th>

<th>Customer Number </th>

<th>Shipping Methode </th>

<th>Salesperson </th>

</tr>'

Set @Message= @Message + @Xml +'</Table></body></html>' 

Exec msdb.dbo.sp_send_dbmail

     @profile_name='Email Alerts',

     @recipients='it@test.com',

     @body=@Message,

     @body_format='HTML',

     @subject='New order has been created';

            

     end

end

 

*This post is locked for comments

  • martink Profile Picture
    890 on at

    Try creating your trigger  on a field in SOP10100 that doesn't update untill it's saved.  

    IF Update (your field ) begin...

    I just created and saved a transaction and then reated a new one, but only went so far as to get the transaction number inserted.  In looking at the data in SOP10100 table there are several possible trigger fields.

  • Suggested answer
    Community Member Profile Picture
    on at

    Have you tried business alerts ?

    Tools>Setup>System>Business Alert

    Cheers!

    Sanjay

  • Community Member Profile Picture
    on at

    I replace (insert) by (update) in my trigger, because when you click on Doc number, there's an insert trigged with inserting blank line with only the SOPNUMBER, i resolve the 1 and 3 problem, it still the order ID next number, do you have any suggession.

  • Community Member Profile Picture
    on at

    good idea but how can i setup, when a new order is created in formulas, second problem i have Dynamics GP2010R2 with office x64 in the same TS, the mail option is not compatible with x64.

  • Richard Whaley Profile Picture
    25,195 on at

    Hmmmm... Business alerts 10 minute setup......custom code...hours.....what's your choice

  • Community Member Profile Picture
    on at

    hello Richard, what do you mean ? it's custom code

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans