Script to find the Contact Code from the Confirm To in Sales Order

SUGGESTED

Hi, I'm trying to write a script to find the Contact Code using the Confirm To in the Sales Order header so that I can populate some user defined fields in the contact code maintenance into the sales order header. I have this so far, but it's not finding my record. Can anyone help me with this?

'if oSession.CompanyCode = "PRT" Then
If oSession.StartProgram = "SO_SALESORDER_UI" Then

Div = ""
CustNo = ""
BTContact = ""
BTContactName = ""
BTContactPh = ""
BTContactExt = ""
BTContactEmail = ""

retVal = oBusObj.GetValue("ARDivisionNo$",Div)
retVal = oBusObj.GetValue("CustomerNo$",CustNo)
retVal = oBusObj.GetValue("ConfirmTo$",BTContactName)

oBillTo = oSession.GetObject("AR_CustomerContact_svc")
if oBillTo <> 0 then
Set oBillTo = oSession.AsObject(oBillTo)

Set oBillTo = oSession.AsObject(oSession.GetObject("AR_CustomerContact_svc"))

retVal = oBillTo.SetIndex("KCONTACTNAME")
retVal = oBillTo.SetKeyValue("ARDivisionNo$", Div)
retVal = oBillTo.SetKeyValue("CustomerNo$", CustNo)
retVal = oBillTo.SetKeyValue("ContactName$", BTContactName)
retVal = oBillTo.Find()
retMsg = oSession.AsObject(oSession.UI).Messagebox("",Div+" "+CustNo+" "+BTContactName)
'If retVal <> 0 then

retVal = oBillTo.GetValue("ContactCode$", BTContact)
retVal = oBillTo.GetValue("ContactName$", BTContactName)
retVal = oBillTo.GetValue("TelephoneNo1$", BTContactPh)
retVal = oBillTo.GetValue("TelephoneExt1$", BTContactExt)
retVal = oBillTo.GetValue("EmailAddress$", BTContactEmail)
retMsg = oSession.AsObject(oSession.UI).Messagebox("",Div+" "+CustNo+" "+BTContactName+" "+BTContactPh)

retVal = oBusObj.SetValue("UDF_BILL_TO_CONTACT_CD$",BTContact)
retVal = oBusObj.SetValue("UDF_BILL_TO_CONTACT$",BTContactName)
retVal = oBusObj.SetValue("UDF_BILL_TO_PHONE$",BTContactPh)
retVal = oBusObj.SetValue("UDF_BILL_TO_EXT$",BTContactExt)
retVal = oBusObj.SetValue("UDF_BILL_TO_EMAIL$",BTContactEmail)

oSession.DropObject("AR_CustomerContact_SVC")

'End If
End If
End If

'End If 'Company Check