Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

SOP Trigger

Posted on by Microsoft Employee

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
    Community Member Microsoft Employee on at
    RE: SOP Trigger

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

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

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

  • Community Member Profile Picture
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee on at
    RE: SOP Trigger

    Have you tried business alerts ?

    Tools>Setup>System>Business Alert

    Cheers!

    Sanjay

  • martink Profile Picture
    martink 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans