Hi Scripters,
I am working with a script to fill in the a/r ship to address for new customers. Basically we have some default addresses that we'd like to add based on the customer division. I have it working ~except~ in testing it is overwriting existing ship-to addresses. Bleh.
' ------------------------- START script code --------------------------------------------------------------
'Title:AR Shipto Default Address Script
'*****
'Desc: Add Shipto 0000 and appropriate address based on division of customer
'*****
'Bus Object: AR Customer Master table
'*****
'Event: Table - Post-write
'*****
'Revision History
'Written by Marc C of Technology Integrators 2016
'****
' ------------------------- START --------------------------------------------------------------
retVal = oScript.DebugPrint(""**Start Script AR Shipto Script.txt***"")
oSO_ShipToAddressBUS = 0
oSO_ShippingRateSVC = 0
retVal = 0
tmpARDivisionNo = """"
tmpCustomerNo = """"
tmpShipToCode = """"
tmpSalesDiv1 = """"
tmpSalesPer1 = """"
udfShipCode = """"
SET oSO_ShipToAddressBUS = oSession.AsObject(oSession.GetObject(""SO_ShipToAddress_bus""))
'SET oSO_ShippingRateSVC = oSession.AsObject(oSession.GetObject(""SO_ShippingRate_svc""))
'Get the values of the current customer the user is on . . . .
retVal = oBusObj.GetValue(""ARDivisionNo$"", tmpARDivisionNo)
retVal = oBusObj.GetValue(""CustomerNo$"", tmpCustomerNo)
retVal = oScript.DebugPrint(""Customer Division is "" & tmpARDivisionNo & ""CustomerNO is "" & tmpCustomerNo)
'this line /area is incorrect???
retVal = oSO_ShipToAddressBUS.getValue(""ShipToCode$"", tmpShipToCode) 'see if there is a shipto code
retVal = oScript.DebugPrint(""Shipto is"" & tmpShipToCode)
'****always returns blank!*************
if tmpShipToCode = """" then
'setup a new shiptocode this always fires since the code is always blank . . .
retVal = oSO_ShipToAddressBUS.SetKeyValue(""ARDivisionNo$"", tmpARDivisionNo)
retVal = oSO_ShipToAddressBUS.SetKeyValue(""CustomerNo$"", tmpCustomerNo)
retVal = oSO_ShipToAddressBUS.SetKeyValue(""ShipToCode$"", ""0000"")
retVal = oSO_ShipToAddressBUS.SetKey()
if retVal <>1 then
retval=oscript.debugprint(""obusobj set key error was"" & oBusObj.LastErrorMsg)
retval=oscript.debugprint(""oso_shipto set key error was"" & oSO_ShipToAddressBUS.LastErrorMsg)
end if
retVal = oScript.DebugPrint(""Script got to point just after setvalues"")
'set the salesperson as the same as the main customer (could be divisional driven if moved to div. subs)
retval = oSO_ShipToAddressBUS.SetValue(""SalespersonDivisionNo$"",tmpSalesDiv1)
retval = oSO_ShipToAddressBUS.SetValue(""SalespersonNo$"",tmpSalesPer1)
if tmpARDivisionNo = ""00"" then
retval = oSO_ShipToAddressBUS.SetValue(""ShipToName$"",""StC"")
retval = oSO_ShipToAddressBUS.SetValue(""ShipToAddress1$"",""2150 Main St W"")
retval = oSO_ShipToAddressBUS.SetValue(""ShipToAddress2$"","""")
retval = oSO_ShipToAddressBUS.SetValue(""ShipToAddress3$"","""")
retval = oSO_ShipToAddressBUS.SetValue(""ShipToCity$"",""Marshall"")
retval = oSO_ShipToAddressBUS.SetValue(""ShipToState$"",""MN"")
retval = oSO_ShipToAddressBUS.SetValue(""ShipToZipCode$"",""56258"")
end if
retval=oSO_ShipToAddressBUS.write
retVal = oScript.DebugPrint(""RetVal after write is now"" & retVal)
end if
' ------------------------- end script code --------------------------------------------------------------
I am not properly querying the shiptoaddressbus apparently - the shipto debug line always shows up blank.
(the retVal = oScript.DebugPrint(""Shipto is"" & tmpShipToCode) line near the beginning of code)
The script does insert the 0000 ship to everytime - and overwrites existing 0000 addresses unfortunately.
Hmm so its partly there. I imagine I need to see if the 0000 shipto code exists (direct query or looping??)then insert in the 0000 if it does not exist.
Any advice is appreciated.
Thank you,
Marc