Having problem adding Customer Contact through BOI

SOLVED

I am running the following VB scripting:

do while not RS3.eof
ARDiv=trim(cstr(rs3("Field1")))
strCustNo=trim(cstr(rs3("Field2")))
strContNo=trim(cstr(rs3("Field3")))
If strContNo="" Then
strContNo=" "
End If

retVAL = oSS.nSetProgram(oSS.nLookupTask("AR_Customer_ui"))
Set oSO = oScript.NewObject("AR_CustomerContact_bus", oSS)

retVal=oSO.nSetKeyValue("ARDivisionNo$",ARDiv)
retVal=oSO.nSetKeyValue("CustomerNo$",strCustNo)
retVal=oSO.nSetKeyValue("ContactCode$",strContNo)
retVal=oSO.nSetKey()
If retVal=0 Then
strMSG2="Customer Number: " & oSS.sLastErrorMsg & vbCRLF
else
strMSG2="Customer Number " & ARDiv & "-" & strCustNo & vbCRLF & "Contact Code:" & strContNo & vbCRLF
End If
strContNam=trim(cstr(rs3("Field4")))
If strContNam<>"" Then
retVal=oSO.nSetValue("ContactName$",strContNam)
If retVal=0 Then
strMSG2=strMsg2 & "Contact Name: " & oSS.sLastErrorMsg & vbCRLF
else
strMSG2=strMsg2 & "Contact Name " & strContNam & vbCRLF
End If
End If
strContA1=trim(cstr(rs3("Field5")))
If strContA1<>"" Then
retVal=oSO.nSetValue("ContactAddressLine1$",strContA1)
If retVal=0 Then
strMSG2=strMsg2 & "Contact Address1: " & oSS.sLastErrorMsg & vbCRLF
else
strMSG2=strMsg2 & "Contact Address1 " & strContA1 & vbCRLF
End If
End If
strContA2=trim(cstr(rs3("Field6")))
If strContA2<>"" Then
retVal=oSO.nSetValue("ContactAddressLine2$",strContA2)
If retVal=0 Then
strMSG2=strMsg2 & "Contact Address2: " & oSS.sLastErrorMsg & vbCRLF
else
strMSG2=strMsg2 & "Contact Address2 " & strContA2 & vbCRLF
End If
End If
strContCity=trim(cstr(rs3("Field7")))
strContState=trim(cstr(rs3("Field8")))
strContZip=trim(cstr(rs3("Field9")))
strContCountry=trim(cstr(rs3("Field10")))
SQL="SELECT * FROM SY_ZipCode WHERE ZipCode='" & strContZip & "'"
Set RS4=Connection2.Execute(SQL)
If RS4.EOF Then
retVAL = oSS.nSetProgram(oSS.nLookupTask("SY_ZipCode_ui"))
Set oZC = oScript.NewObject("SY_ZipCode_bus", oSS)
retVal=oZC.nSetKeyValue("ZipCode$",strContZip)
retVal=oZC.nSetKey
retVal=oZC.nSetValue("City$",strContCity)
retVal=oZC.nSetValue("StateCode$",strContState)
retVal=oZC.nSetValue("CountryCode$",strContCountry)
retVal=oZC.nWrite()
End If
retVal=oSO.nSetValue("City$",strContCity)
If retVal=0 Then
strMSG2=strMsg2 & "Contact City: " & oSS.sLastErrorMsg & vbCRLF
else
strMSG2=strMsg2 & "Contact City " & strContCity & vbCRLF
End If
retVal=oSO.nSetValue("State$",strContState)
If retVal=0 Then
strMSG2=strMsg2 & "Contact State: " & oSS.sLastErrorMsg & vbCRLF
else
strMSG2=strMsg2 & "Contact State " & strContState & vbCRLF
End If
retVal=oSO.nSetValue("ZipCode$",strContZip)
If retVal=0 Then
strMSG2=strMsg2 & "Contact Zip Code: " & oSS.sLastErrorMsg & vbCRLF
else
strMSG2=strMsg2 & "Contact Zip Code " & strContZip & vbCRLF
End If
retVal=oSO.nSetValue("CountryCode$",strContCountry)
If retVal=0 Then
strMSG2=strMsg2 & "Contact Country: " & oSS.sLastErrorMsg & vbCRLF
else
strMSG2=strMsg2 & "Contact Country " & strContCountry & vbCRLF
End If
strContPhone=trim(cstr(rs3("Field11")))
If strContPhone<>"" Then
retVal=oSO.nSetValue("Telephone1$",strContPhone)
If retVal=0 Then
strMSG2=strMsg2 & "Contact Phone: " & oSS.sLastErrorMsg & vbCRLF
else
strMSG2=strMsg2 & "Contact Phone " & strContPhone & vbCRLF
End If
End If
strContEmail=trim(cstr(rs3("Field13")))
retVal=oSO.nSetValue("EmailAddress$",strContEmail)
If retVal=0 Then
strMSG2=strMsg2 & "Contact Email: " & oSS.sLastErrorMsg & vbCRLF
else
strMSG2=strMsg2 & "Contact Email " & strContEmail & vbCRLF
End If

retVal=oSO.nWrite()
If retVal=0 Then
dblF=1
strEdErr2=oSO.sLastErrorMsg
End If

uns fine on my local system and the contact is created (Sage 2018 Standard v 6.00.5), but when I run it on my customers system (Sage 2018 Premium v 6.00.5) I receive the error "Module I/T is not on file" and "The record is not in an editable state.".

The customer does not have eBusiness installed on their server at all. I can create the customer contact through the UI without error.

  • +1
    verified answer

    Your pasted code is missing the closing "Loop" statement for your "Do..While" structure.

    Also, on all of the lines where you are building the strMsg2 variables using the sLastErrorMsg property, you are doing so using the wrong object handle, you are using oSS when you should be using the object who's error you are wanting to check, in this case, it should be the oSO object because that is the one you are using all the methods against.

    IIRC, VBScript's CStr function does not handle NULL so if you are returning values from a record set that could potentially contain NULL, you can use CStr("" & rs3("Field1")) to make sure NULL is converted to an empty string.

    There is also no point proceeding with setting values and using nWrite if the nSetKey failed, ideally, you would only proceed if nSetKey returned 2 (new record) or a 1 (existing record), if it was a -1, then the object's sLastErrorMsg should contain the reason you got a -1. I do not recall if a -1 on a SetKey always means you should not proceed with setting values and writing, but if it was because the record was in use by another user, then depending on the object, such as with invoicing, your changes wouldn't be saved anyway. If it was for a sales order and the reason was that the sales order is currently being invoiced, you changes wouldn't be saved.