Skip to main content

Notifications

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

  • Community Member Profile Picture
    on at
    RE: SOP Trigger

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

  • Richard Whaley Profile Picture
    25,195 on at
    RE: SOP Trigger

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

  • Community Member Profile Picture
    on at
    RE: SOP Trigger

    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.

  • Community Member Profile Picture
    on at
    RE: SOP Trigger

    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.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: SOP Trigger

    Have you tried business alerts ?

    Tools>Setup>System>Business Alert

    Cheers!

    Sanjay

  • martink Profile Picture
    890 on at
    RE: SOP Trigger

    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.

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
Almas Mahfooz Profile Picture

Almas Mahfooz 3 User Group Leader

Featured topics

Product updates

Dynamics 365 release plans