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

  • 0

    Is this script attached to post-validate of confirm to?  or somewhere else?  The confirm to field gets populated with the contact name which when retrieved may not match the contact code.    However, if you want to use the customer name index you probably can accomplish what you want to do.

    Elliott

  • 0
    SUGGESTED

    I'd open the contact object, set a browse filter of the Division and CustomerNo (without having to change the browse index), then loop through all that customer's contacts looking for the correct name.  Since you don't know the ContactCode field value you can't go directly there.

    You could also try GetResultSets for the lookup, but that function is incredibly tricky to get set up correctly.