Hi Forum,
I need to update a ship to address code "0000" when a new cusotmer is created. I am trying to do it on a "pre-write event" is entered but I am getting an error.
Any suggestions ?
Regards,
Manuel Roman
Still getting the same message. Here is the code I am using.
sCust = "" : strCustno = "" : strDiv = "" : sMemoCode = "" : sMemoDescription = "" : sCustomerNo = "" : newDate = "" : sCertCustExpire = "" : sCertExpire = "" : strShipToCode= "0000" : sStatus = "" : strShipToName = "" : strAddr1 = "" : strAddr2 = "" : strAddr3 = "" : strCity = "" : strState = "" : strZipCode = "" : strCountryCode = ""
sCompany = oSession.CompanyCode
sUsercode = oSession.UserCode
'------------------- Instantiate Ship To Object ---------------------------
Set oUIObj = oSession.AsObject(oSession.GetObject("SO_ShipToAddress_ui"))
Set oShipTo = oSession.AsObject(oSession.GetObject("SO_ShipToAddress_svc"))
'--------------------------------------------------------------------------
'if sCompany = "TST" then
'sMsg = "Company: " & sCompany & " Date = " & newDate & vbCRLF
'msgRetVal = oSession.AsObject(oSession.UI).MessageBox("", sMsg) ' Displays the message box
if oBusObj.EditState = 2 Then
'---------------- Ship To Code --------------------------------------
retVal = oBusObj.GetValue("ARDivisionNo$", strDiv)
retVal = oBusObj.GetValue("CustomerNo$", strCustno)
retVal = oShipTo.SetKeyValue("ARDivisionNo$", strDiv)
retVal = oShipTo.SetKeyValue("CustomerNo$", strCustno)
retVal = oShipTo.SetKeyValue("ShipToCode$", strShipToCode)
retVal = oShipTo.SetKey()
if retVal = 0 then
sMsg = "Not able to SetKey for Customer No: " & strDiv & " " & strCustno & " " & strShipToCode & oShipTo.LastErrorMSG & vbCRLF
msgRetVal = oSession.AsObject(oSession.UI).MessageBox("Not Able to Create Ship To", sMsg) ' Displays the message box
end if
retVal = oBusObj.GetValue("CustomerName$", strShipToName)
retVal = oBusObj.GetValue("AddressLine1$", strAddr1)
retVal = oBusObj.GetValue("AddressLine2$", strAddr2)
retVal = oBusObj.GetValue("AddressLine3$", strAddr3)
retVal = oBusObj.GetValue("City$", strCity)
retVal = oBusObj.GetValue("State$", strState)
retVal = oBusObj.GetValue("ZipCode$", strZip)
retVal = oBusObj.GetValue("CountryCode$", strCountryCode)
'retVal = oShipTo.SetValue("ShipToCode$", strShipToCode)
retVal = oShipTo.SetValue("ShipToName$", strShipToName)
retVal = oShipTo.SetValue("ShipToAddress1$", strAddr1)
retVal = oShipTo.SetValue("ShipToAddress2$", strAddr2)
retVal = oShipTo.SetValue("ShipToAddress3$", strAddr3)
retVal = oShipTo.SetValue("ShipToCity$", strCity)
retVal = oShipTo.SetValue("ShipToState$", strState)
retVal = oShipTo.SetValue("ShipToZipCode$", strZip)
retVal = oShipTo.SetValue("ShipToCountryCode$", strCountryCode)
r = oShipTo.Write()
If r = 0 then
sMsg = "Not able to write Ship To Code: " & oShipTo.LastErrorMSG & vbCRLF
msgRetVal = oSession.AsObject(oSession.UI).MessageBox("", sMsg) ' Displays the message box
End if
end if
'end if
Regards,
Manuel
Got it.... my bad. using the wrong Object
Set oShipTo = oSession.AsObject(oSession.GetObject("SO_ShipToAddress_svc")), changed it to "bus"
But you were right, it is Post-Write. The customer needs to exist....
Thanks Kevin!!!