You are accessing the Members Only area for DynDeveloper.com using guest access. The member experience is slightly different
stevegray
4Penny.net
Points: 55409

11/14/2019 12:13:48 PM

Duplicate master numbers in GP 2016/2018 sopGetMasterNumber

* This article, and all our great .NET Development documentation, Is available on the .NET Development menu

As far as I can tell, this has been going on for a very long time. 

https://community.dynamics.com/gp/f/microsoft-dynamics-gp-forum/156823/sop-entry-duplicate-master-number

https://support.microsoft.com/en-us/help/856311/multiple-customers-have-documents-that-reference-the-same-master-numbe

http://timwappat.info/post/2009/06/19/Duplicate-SOP-Master-number-in-Dynamics-GP

 

A client called today for help, and I printed out the current 'get next master' code and... it didn't make sense. That doesn't mean it's not right... it just didn't make sense. it was conditionally creating a transaction. 

The code below avoids that, and always creates a transaction. 

Please... if you you use this, test it carefully and get back to me if it works, or if it doesn't. I'd like to know.

4Penny.net
Version: Unknown or N/A
Section: Dynamics GP

 

DROP PROCEDURE sopGetMasterNumber
GO
  
CREATE PROCEDURE sopGetMasterNumber
  
@O_iOUTMasterNumber int = NULL OUTPUT,
@O_iErrorState int = NULL OUTPUT
  
AS
DECLARE @tTransaction tinyint,
                @iError int
  
SELECT
                @O_iOUTMasterNumber = 0,
                @O_iErrorState = 0
  
BEGIN TRY
    BEGIN TRAN
        -- be carefull not to exit this or the transaction will not get committed, you'll lock the table up
                                UPDATE SOP40100 SET
                                                @O_iOUTMasterNumber = NXTMSTNO,
                                                NXTMSTNO = NXTMSTNO + 1
  
                                --declare @a int = 0
                                --declare @b int
                                --set @b = 5 / @a
  
    COMMIT TRAN
END TRY
BEGIN CATCH
    --find out what went wrong
    --SELECT
    --    ERROR_NUMBER() AS ErrorNumber,
    --    ERROR_SEVERITY() AS ErrorSeverity,
    --    ERROR_STATE() AS ErrorState,
    --    ERROR_PROCEDURE() AS ErrorProcedure,
    --    ERROR_LINE() AS ErrorLine,
    --    ERROR_MESSAGE() AS ErrorMessage;
  
    --roll everything back
    ROLLBACK TRAN
  
                select @O_iOUTMasterNumber = 0, @O_iErrorState = 21035
END CATCH
  
  
RETURN
go
grant exec on sopGetMasterNumber to dyngrp

 

 

Please leave a comment

Add a Comment



Not Subscribed. You will not receive emails on article changes or comment additions

Comments

body header
No records to display.
Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3