Button Option on SO Invoice Entry for Batched Orders

SUGGESTED

I have two scripts running on the SO Invoice Date Entry Header, one on a pre-totals to change the "MultipleSalesOrdersApplied$" field to "N", this works no matter if there is more than one SO applied to the invoice.  My next script is a post read to change the "MultipleSalesOrdersApplied$" to "Y", however the way I have the script it is changing it to "Y" even if I only have one order applied to the invoice.  Could I put a button that ask the user if they want to change it back to "Y" (never did a button script).  Or could my script be adjusted somehow to only set the "MultipleSalesOrdersApplied$" field to "Y" if ....?

The SO's that need these scripts to fire never have a shiptocode and all start with the SO# "81".

'initialize variables pre-totals on shiptocode

retVal = 0
sShipTo = ""

retVal = oBusObj.GetValue("ShipToCode", sShipTo)

if sShipTo = "" then

	retVal = oBusObj.SetValueNoValidate("MultipleSalesOrdersApplied$", "N")
	
end if

'change read only field back to default value for multiple SO invoice

retVal = 0
nSOno = ""

retVal = oBusObj.GetValue("SalesOrderNo$", nSOno)

if Left(nSOno, 2) = "81" then

	retVal = oBusObj.SetValueNoValidate("MultipleSalesOrdersApplied$", "Y")
	
end if

  • 0
    SUGGESTED

    That isn't a field you should normally have to change as the business object should make sure it is set correctly when the right conditions are met.

    If you must change it, I would suggest evaluating the result of the ValidateGroupMultipleSO() method.  If it returns 0, multiple SOs have been applied, if it returns 1, it either only has one SO applied or it doesn't have an SO applied.

  • 0 in reply to David_Speck

    I am struggling on how to evaluate the result of ValidateGroupMultipleSO().  Do you use BusObj to get the variable?

  • 0 in reply to jland47

    nRetVal = 0 : nRetVal = oBusObj.ValidateGroupMultipleSO()
    If nRetVal = 0 Then
        ' Multiple SOs applied.
    Else 
        ' One or no SOs applied.
    End If

  • 0 in reply to David_Speck

    Trying to message box where the issue is, but I get the Company code return then the script just errors out.  And it does this when right when I create a new invoice or when I pull up a previous one.

    If oSession.CompanyCode = "ROI" then
    retval = oSession.AsObject(oSession.UI).Messagebox( ".company", oSession.CompanyCode)
    
    retVal = 0
    multiSO = ""
    multiSO = oBusObj.ValidateGroupMultipleSO()
    retval = oSession.AsObject(oSession.UI).Messagebox( "multi", multiSO)
    
    	If multiSO = 0 then
    
    	retVal = 0
    	nSOno = ""
    
    	retVal = oBusObj.GetValue("SalesOrderNo$", nSOno)
    
    		if Left(nSOno, 2) = "81" then
    
    		retVal = oBusObj.SetValueNoValidate("MultipleSalesOrdersApplied$", "Y")
    
    		Else
    
    		retVal = oBusObj.GetValue("SalesOrderNo$", nSOno)
    
    		retVal = oBusObj.SetValueNoValidate("MultipleSalesOrdersApplied$", "N")
    
    		end if
    	end if	
    end if

  • 0 in reply to jland47

    Couple issues.

    ValidateGroupMultipleSO() returns a numeric value so your multiSO variable should be initialized to 0 not an empty string.

    The MessageBox method only accepts string values passed to it.  You also don't have a valid value in the first argument, use a blank string instead ("").  For the second argument, use CStr() on your multiSO variable or join it to an empty string using the & operator, like "" & multiSO.

  • 0 in reply to David_Speck

    This shows my lack of knowledge, completely lost on your last explanation, but did get it to work.  It only works when I close the Invoice data entry screen and reopen the batch.  If you don't mind could you point out the exact corrections you were referring to above.  This is the version I got to work on a table post-read.

    'change read only field back to default value for multiple SO invoice
    
    If oSession.CompanyCode = "ROI" then
    
    retVal = 0
    retVal = oBusObj.ValidateGroupMultipleSO()
    
    	If retVal = 0 then
    
    	retVal = 0
    	nSOno = ""
    
    	retVal = oBusObj.GetValue("SalesOrderNo$", nSOno)
    
    		if Left(nSOno, 2) = "81" then
    
    		retVal = oBusObj.SetValueNoValidate("MultipleSalesOrdersApplied$", "Y")
    
    		Else
    
    		retVal = oBusObj.GetValue("SalesOrderNo$", nSOno)
    
    		retVal = oBusObj.SetValueNoValidate("MultipleSalesOrdersApplied$", "N")
    
    		end if
    	end if	
    end if