Launch Sales Order Entry to create new order from Customer Maintenance and pass Customer Number

SOLVED

Hi Sage City and Happy Friday!

I have been working on a button script to launch Sales Order Entry from AR Customer Maintenance.  The goal is to click on the button and open SO Entry, automatically select the next Order Number and pass the Customer Number to it.  I thought it was simple enough but I cannot pass the Customer Number for some reason.

Here is what I have.  I created a new button in AR Customer Main.  It is linked to the script below

oSOEntry = 0
DivNo = ""
CustNo = ""
oSessionScript = 0
sPopupFlag = 0
SODivNo = ""
SOCustNo = ""
sFlag = 1
CustNumber = ""

oSOEntry = oSession.GetObject("SO_SalesOrder_UI")
retVal = oBusObj.GetValue("ARDivisionNo$",DivNo)
retVal = oBusObj.GetValue("CustomerNo$",CustNo)

CustNumber = DivNo&"-"&CustNo

oScript.DebugPrint CustNumber

if oSOEntry <> 0 then
	Set oSessionScript = oSession.AsObject(oSession.ScriptObject)
	retVal = oSessionScript.SetStorageVar("sPopupFlag", sFlag)
	retVal = oSessionScript.SetStorageVar("SODivNo", DivNo)
	retVal = oSessionScript.SetStorageVar("SOCustNo",CustNo)
	retVal = oSessionScript.SetStorageVar("CustNumber",CustNumber)
	oScript.DebugPrint DivNo & "-" & CustNo
	Set oSOEntry = oSession.AsObject(oSOEntry)
	retVal = oSOEntry.Process()

End if

Everything is good to go up to this point.  Then, I have the following Panel-PostLoad script on PHEADER of Sales Order Entry (it wouldn't work on DMAIN for some reason)

sFlag = 0
sPopupFlag = 0
oSessionScript = 0
SODivNo = ""
SOCustNo = ""
DivNo = ""
CustNo = ""
CustNumber = ""

Set oSessionScript = oSession.AsObject(oSession.ScriptObject)
retVal = oSessionScript.GetStorageVar("sPopupFlag",sFlag)
retVal = oSessionScript.GetStorageVar("SODivNo", DivNo)
retVal = oSessionScript.GetStorageVar("SOCustNo",CustNo)
retVal = oSessionScript.GetStorageVar("CustNumber", CustNumber)
oScript.DebugPrint "sFlag= " & sFlag & " Div= " & DivNo & " CustNo= " & CustNo
oScript.DebugPrint CustNumber

if sFlag <> 0 and sScriptRun = 0 Then
	sFlag = 0 : retVal = oSessionScript.SetStorageVar("sPopupFlag",sFlag)
	retVal = oScript.InvokeButton("BT_NEXTNUM")
	retVal = oBusObj.SetValue("ARDivisionNo$", DivNo)
	retVal = oBusObj.SetValue("CustomerNo$",CustNo)
	oScript.DebugPrint oBusObj.LastErrorMsg
	
end if

When I click the button from Customer Maintenance, it is definitely getting the Division and Customer number and setting it into StorageVar.  The Panel-Postload script is getting the variables as it launches the screen and clicks on the "Next SO number" button.  However, I cannot get it to set the Division Number and Customer number.  I tried to set "oBusObj.Write()" after setting the values but that didn't work either since I assume that's writing the whole record and it's missing a whole bunch of info.
Maybe I have the script in the wrong place (DMAIN instead of PHEADER) and I need to use a different method?  Or maybe I need to use InvokeProgram but I thought you couldn't pass variables that way?  
Any ideas would be greatly appreciated.
Thanks!

Javier

  • 0 in reply to David Speck

    Thanks for that tip, David.  I decided to do a oScript.DebugPrint oSOPrint.LastErrorMsg just about everywhere there is a call to it.  Here is what I found

    For giggles, I decided to change the .SelectReportSetting to "Standard" and I didn't get any errors until the very last 2 after the ProcessReport, which were the the same values as before = "10000036" and "Select a Template to Use".  Unfortunately, nothing prints to either a printer or anything so it's hard to tell what it's trying to print.

  • 0 in reply to David Speck

    One last test:  If I change the nSOPrint to a string, then try to do a oScript.DebugPrint nSOPrint.LastErrorMsg after calling the oSession.NewObject("SO_SalesOrderPrinting_rpt"), I get an error 88 Invalid/Unknown Property Name - Object required: nSOPrint.  Funny enough, I still get "100237" value when calling oScript.DebugPrint "nSOPrint: " & nSOPrint
    Sounds like even though we are calling the SO_SalesOrderPrinting_rpt, it is not working when launched through AR Customer?

  • +1 in reply to Javier Guzman
    verified answer

    the oSession.AsObject method expects the argument passed to it to be a numeric value, converting it to a string will cause it to fail.

    You may need to store the current module in your AR script and then use oSession.SetModule to set it to the sales order module followed by oSession.SetProgram like i described in previous post.  Some programs expect certain properties to be set and that only happens when you do things in the correct order.  Then, once your AR script resumes, set the module back to accounts receivable followed by SetProgram like i described in previous post.

  • 0 in reply to David Speck

    Cool, let me work on that.  Thanks as always, David,  I appreciate your time and insight.

  • 0 in reply to David Speck

    David, I just wanted to follow up on this.  As always, you have the right answers!
    I was able to get it working just like you described on the post above.

    I had a minor issue but I was able to fix it: After clicking the button in Customer Maintenance, creating the new SO and accepting it, it now processes the QuickPrint SO script beautifully.  However, if I closed the SO entry window and went back to Customer Maintenance and I modified the record in any way (e.g.: update phone number or contact or address) and tried to accept it, the message "Record - has been changed by another user and the changes will not be saved." popped up.
    In order to fix this, all I had to do was to call the record again at the end of the AR script.
    Here is the final script in case anyone else needs it in the future.

    oSOEntry = 0
    DivNo = ""
    CustNo = ""
    oSessionScript = 0
    sPopupFlag = 0
    sFlag = 1
    CustNumber = ""
    
    nOriginalStartTask = 0 : nOriginalTask = oSession.StartTask
    oSOEntry = oSession.GetObject("SO_SalesOrder_UI")
    retVal = oBusObj.GetValue("ARDivisionNo$",DivNo)
    retVal = oBusObj.GetValue("CustomerNo$",CustNo)
    
    CustNumber = DivNo&CustNo
    
    oScript.DebugPrint CustNumber
    
    if oSOEntry <> 0 then
    	Set oSessionScript = oSession.AsObject(oSession.ScriptObject)
    	retVal = oSessionScript.SetStorageVar("sPopupFlag", sFlag)
    	retVal = oSessionScript.SetStorageVar("CustNumber",CustNumber)
    	oScript.DebugPrint "CustNumber: " & CustNumber
    	retVal = oSession.SetModule("S/O")
    	retVal = oSession.SetProgram(oSession.LookupTask("SO_SalesOrder_UI"))
    	Set oSOEntry = oSession.AsObject(oSOEntry)
    	retVal = oSOEntry.Process()
    	Set oSOEntry = Nothing
    	retVal = oSession.SetModule("A/R")
    	retVal = oSession.SetProgram(nOriginalStartTask)
    	retVal = oBusObj.SetKey(CustNumber)
    
    End if


    Thanks again, David!  You are truly a rockstar.

  • 0 in reply to Javier Guzman

    Sounds like Sage is internally updating the customer record with something after the new order is created.  You can use SetKey like you are but that won't cause any variables on screen to refresh if they truly did change.  Now that you know this is happening, you should actually look to see if you are in customer inquiry or maintenance, the oBusObj.SecurityAccess property should indicate which level of access the button script has.  If 0, it should be inquiry, if greater than 0, you should check the oBusObj.RecordChanged property, if 0, use oUIObj.BT_Cancel, if 1, you should prompt the user if they want to save changes using the MessageBox method and check the returned value to see if they answered yes or no, if no, use oUIObj.BT_Cancel, if yes, use and check the returned value of oUIObj.BT_Accept(), if 1, proceed with your script to change the start program to sales order entry and launch it, if less than 1, sage 100 should display a message box to the user with the reason it failed, your script should do nothing if this is the case.  The user will have to correct whatever caused it to fail on click your button again and choose not to save the changes.  Once you get back from sales order entry, you should use oUIObj.InvokeChange "ML_Customer", [ARDivisionNo + CustomerNo].  Using the UI object's methods should make sure your screen updates to reflect any changes.