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

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Updating the batch ID on a sales transaction in SQL?

(0) ShareShare
ReportReport
Posted on by 255

Is there a stored procedure (or set of) to do accomplish this?  Is it safe to simply update sop10100 and ... whatever the batch header table is? (SY00500?)  Or will I be overlooking other processes if I do so ... 

 

Thanks!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Tim Foster Profile Picture
    8,515 on at
    Re: Updating the batch ID on a sales transaction in SQL?

    See the post by Mariano Gomez at:

    dynamicsgpblogster.blogspot.com/.../moving-sop-transactions-from-one-batch.html

    Tim Foster

  • Jon Wire Profile Picture
    255 on at
    Re: Updating the batch ID on a sales transaction in SQL?

    Gotcha -- that looks good.  I'm also a little concerned about two phenomena with our current solution, which is not correctly updating the batch header.  Currently, some orders are opening without batch ID's after being updated.  And then when our fulfillment team enters "SHIPPED" in the batch ID field, they are prompted to create the batch -- *every* time.  Looking at sy00500, the batch no longer seems to exist.

    Any thoughts?  Should I post my code?  (there's a fair amount of it)

     

    CORRECION: the SHIPPED batch does appear in SY005500 ... but, users are still being occasionally being prompted to create the batch when they enter it.

  • Tim Foster Profile Picture
    8,515 on at
    Re: Updating the batch ID on a sales transaction in SQL?

    I suppose I could look...

    Why is there so much code?

    TIm Foster

  • Jon Wire Profile Picture
    255 on at
    Re: Updating the batch ID on a sales transaction in SQL?

    In looking at it, I think the majority of the code is interaction with other systems -- the GP portion is the minority.  As you may have gathered, the code moves orders to a SHIPPED batch -- it's a web service for our fulfillment company to connect to.  Sparing you the bulk of it, here's the GP DB interaction:

     

    *********** START CODE ***********

    #region check GP database for the order

     

    // verify the order exists in GP

    SqlCommand query = new SqlCommand(

    "select 1 from dbo.sop10100 where sopnumbe='" + SqlEscape(OrderID) + "' and soptype=2",

    Global.gpdb

    );

    Int32 result = Convert.ToInt32(query.ExecuteScalar());

    if (result < 1)

    {

    // if the order cannot be found, update the log entry with an ORDER NOT FOUND

    return new LoggedServiceResponse(logger.LogEntryId, "The order could not be found.", false);

    }

     

    #endregion check GP database for the order

     

     

    #region check GP database for records in USER DEFINED table

     

    // verify the order exists in GP

    query = new SqlCommand(

    "select 1 from dbo.sop10106 where sopnumbe='" + SqlEscape(OrderID) + "' and soptype=2",

    Global.gpdb

    );

    result = Convert.ToInt32(query.ExecuteScalar());

    if (result < 1)

    {

    // if the order cannot be found, update the log entry with an ORDER NOT FOUND

    return new LoggedServiceResponse(logger.LogEntryId, "The order was found, but was never successfully submitted for fulfillment.", false);

    }

     

    #endregion check GP database for records in USER DEFINED table

     

     

    #region update date, method, and price fields

    String updateOrderValues = "update dbo.sop10106 set usrdat02=@ship_date, userdef1=@ship_method, userdef2=@ship_cost where sopnumbe=@order_id and soptype=2";

    query = new SqlCommand(updateOrderValues, Global.gpdb);

    query.Parameters.Add(new SqlParameter("@ship_date", ShipDate));

    query.Parameters.Add(new SqlParameter("@ship_method", ShipMethod));

    query.Parameters.Add(new SqlParameter("@ship_cost", ShipCost));

    query.Parameters.Add(new SqlParameter("@order_id", OrderID));

    query.ExecuteNonQuery();

    #endregion update date, method, and price fields

     

     

    #region update the batch number

    String updateOrderBatch = "update dbo.sop10100 set bachnumb=@batch where sopnumbe=@order_id and soptype=2";

    query = new SqlCommand(updateOrderBatch, Global.gpdb);

    query.Parameters.Add(new SqlParameter("@order_id", OrderID));

    query.Parameters.Add(new SqlParameter("@batch", "SHIPPED"));

    query.ExecuteNonQuery();

    #endregion update the batch number

     

     

    #region insert tracking numbers

    String removeExistingTrackingNumbers = "delete from dbo.sop10107 where sopnumbe=@order_id and soptype=2";

    query = new SqlCommand(removeExistingTrackingNumbers, Global.gpdb);

    query.Parameters.Add(new SqlParameter("@order_id", OrderID));

    query.ExecuteNonQuery();

     

    if (TrackingNumbers.Length > 0)

    {

    // de-dupe tracking numbers?

     

    String insertTrackingNumber = "BEGIN TRY insert into dbo.sop10107 (soptype, sopnumbe, Tracking_number) values (2, @order_id, @tracking_number); END TRY BEGIN CATCH END CATCH;";

    query = new SqlCommand(insertTrackingNumber, Global.gpdb);

    query.Parameters.Add(new SqlParameter("@order_id", OrderID));

    query.Parameters.Add(new SqlParameter("@tracking_number", "this string still be removed."));

    for (int i = 0; i < TrackingNumbers.Length; i++)

    {

    query.Parameters.RemoveAt("@tracking_number");

    query.Parameters.Add(new SqlParameter("@tracking_number", TrackingNumbers[i]));

    query.ExecuteNonQuery();

    }

    }

    #endregion insert tracking numbers

     

    *********** END CODE ***********

     

    That should be it for GP-related code.  Sorry about any formatting issues -- I'm not sure of the best way to format code in this forum.

     

    Thanks for the help!

  • Tim Foster Profile Picture
    8,515 on at
    Re: Updating the batch ID on a sales transaction in SQL?

    When does this service run?  Does it run while users are actively working?  On a BASIC level this code will work, but it ignores many things:

    Is the order attempting to be updated in use by a user?

    The batch totals where the order is now are not updated.

    The batch totals where the order is moved to are not updated.

    Does the batch "SHIPPED" even exist when you "move" an order to it? If user POST the "SHIPPED" batch, it is removed (deleted).  (Hence your users being prompted to create it, even though there are orders "in" it already.)

    Yikes!

    Tim Foster

  • Jon Wire Profile Picture
    255 on at
    Re: Updating the batch ID on a sales transaction in SQL?

    Got it.  I was unaware that batches were removed entirely when they get posted.

     

    So, the code you linked me will help me solve the last 3 issues.  The first issue shouldn't be a concern, but it should definitely be addressed -- just in case.  Where are locks/opens stored?

     

    Thanks!

  • Jon Wire Profile Picture
    255 on at
    Re: Updating the batch ID on a sales transaction in SQL?

    Sorry to re-post ... but ...

    Do I need to worry about potential damage to the resulting financials with the code in place as it is?  Do the values on the batch headers get used for anything important -- or are they simply informational at the batch level?

  • Tim Foster Profile Picture
    8,515 on at
    Re: Updating the batch ID on a sales transaction in SQL?

    Locks:

    Tempdb.dbo.DEX_LOCK - Table and row lock by Dex_row_id

    DYNAMICS.dbo.SY00800 - Batch Locks

    DYNAMICS.dbo.SY00801 - Resource/Document

    I would target DEX_LOCK for SOP10100

    Batch header is informational.  I don't think there is a risk of damage to anything - just bad information.

    Tim Foster

  • Jon Wire Profile Picture
    255 on at
    Re: Updating the batch ID on a sales transaction in SQL?

    Excellent.  Thanks for your help, sir!  It is very much appreciated.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans