Message Box Showing Up Even When Intended Criteria is not Met

SOLVED

Hi,

A few days ago I had a Post that I was lucky enough to get help with. After getting some feedback from some of our shipping department, they let me know that even if they go in and change the Ship Date in Sales Order Entry, the message box will still pop-up. I thought maybe it was because the order's ship date was original older than today's date. But after creating some test orders with ship dates a week from today, I realized this message box is showing up no matter what. I attached the code I was using which again, I got from the original post, the only change being what I wanted in the message box. Maybe I'm missing something in this script that is causing the message box to show up no matter what but does anyone have any ideas?

sShipExpireDate = "" : oBusObj.GetValue "ShipExpireDate$", sShipExpireDate

	
	If oSession.UI <> 0 And sShipExpireDate < oSession.SystemDate Then

		oSession.AsObject(oSession.UI).MessageBox "", "Ship Date is Past Due. If necessary, change the Ship Date in Sales Order Entry."

	End If

  • 0

    I'd do a pop-up (as a test) to check what's in sShipExpireDate and the result of oSession.SystemDate.  (Remembering that the "<" comparison in VBScript is a string comparison, not a date comparison).

    Scripted dates in Sage are not always intuitive, nor in the format you might expect.

  • 0 in reply to Kevin M

    The other thing is that the SO_InvoiceHeader does not have a "ShipExpireDate" that column belongs to the Sales Order Header.  The soHdr.ShipExpireDate gets mapped to soInv.ShipDate.  So that is likely the column you want to compare to, not ShipExpireDate.

  • 0 in reply to jepritch

    Good catch.  I have made that mistake (using the wrong field name) more times than I care to admit... (which is why I am now in the habit of using pop-ups during testing, to verify values are what I think they should be).

  • 0 in reply to jepritch

    Jerrad, I used the field name in your other post without double checking it so I apologize for that.  

    Your other post was for Shipping Data Entry and in this post, you said it is for Sales Order Entry.

    As jepritch pointed out, you would need to change the field name based on the table.

    So if your script is on SO_InvoiceHeader, you should use ShipDate$ but if it is on SO_SalesOrderHeader, then you should use ShipExpireDate$.

    Also, as Kevin pointed out, dates in Sage 100 are stored as strings in YYYYMMDD format so you have to account for this when doing comparisons.  What is likely happening is that since the wrong field was passed, you are getting an empty string back, which happens to be "less than" ANY date returned by oSession.SystemDate and this is causing the message to appear every time.

  • 0 in reply to David Speck

    I may not have been very clear in the post. I'd like the message box to show up while in Shipping Data Entry but wanted the script to reference the Ship Date in Sales Order Entry, sorry about that. If I wanted the message box to show up when I put the Order Number in Shipping Data Entry, I'm assuming it has to be under SO_InvoiceHeader, right?

  • 0 in reply to Jerrad Garrett

    Then it sounds like you should put the script on the SO_InvoiceHeader table on the post-validate event of the SalesOrderNo field and you should have it reference ShipDate$.

  • 0 in reply to David Speck

    I used the pop-ups to test what values I was getting back like Kevin recommended and I didn't get the value I wanted with either ShipDate$ or ShipExpireDate$. 

    To preface, I made a test order with the Ship Date set to 1/29/2022 and had the script in the SO_InvoiceHeader table. When the script referenced ShipDate$, it came back with the value of 1/25/2022. I would like it to come back with the expected Ship Date value of 1/29/2022 that I set in Sales Order Entry. When the script referenced ShipExpireDate$ it came back with a blank value. I'm assuming the second came back blank, like jepritch said, because there is no ShipExpireDate column in SO_InvoiceHeader.

    If I have the script reference ShipExpireDate$ and put the script in the SO_SalesOrderHeader, can I still get the message box show up when I am opening the order in Shipping Data Entry? There's no option for the script to trigger post-validating the SalesOrderNo when putting the script in SO_SalesOrderHeader.

    The script seems to work fine besides the fact that it is referencing the Ship Date in Shipping Data Entry (the actual day of shipment) instead of the Ship Date in Sales Order Entry (our expected ship date/promise date). I'd like to compare the system date/actual ship date vs the promise date.

  • +1 in reply to Jerrad Garrett
    verified answer

    Having the script on SO_SalesOrderHeader will not help because the script won't trigger when you need it.

    What event do you currently have it assigned to on SO_InvoiceHeader?

    If on the post-validate of the SalesOrderNo field, it is possible that the ShipDate$ hasn't been populated yet with the value from the sales order source document.  If this is the case, you may need to use the following.

    oBusObj.ReadAdditional "SalesOrderNo"
    sShipExpireDate = "" : oSession.AsObject(oBusObj.GetChildHandle("SalesOrderNo")).GetValue "ShipExpireDate$", sShipExpireDate
    If oSession.UI <> 0 And sShipExpireDate < oSession.SystemDate Then
    	oSession.AsObject(oSession.UI).MessageBox "", "Ship Date is Past Due. If necessary, change the Ship Date in Sales Order Entry."
    End If

    You could instead put the script on the pre-write event of SO_InvoiceHeader and then it could reference the ShipDate$ field in SO_InvoiceHeader because at the point when the script is triggered, the ShipDate field should definitely have a value AND since it is checking the ship date of the actual shipping entry, if the user does adjust it accordingly, they won't get the message. 

    Keep in mind though that a change to the ShipDate in shipping data entry will not update the ShipExpireDate in sales order entry.

  • 0 in reply to David Speck

    I copied that code and tweaked it as I need it and from what I see, works perfectly fine. I don't think our shippers really change the ship date in Shipping Data Entry much so I'm not sure it is necessary, but if I find out differently I will implement that, as I definitely understand how that could be useful. Thanks for all your help. I'm sure if I have more problems with this or other little projects, I'll be back. Thanks.

  • 0 in reply to Jerrad Garrett

    Hi Jerrad, happy to see that the community helped you figure out a solution!Tada

    If you have a minute, tell us about your great experience on Sage City, take this short 3 question survey