Running into an issue with writing a PO Receipt of Invoice thru the Business Object Interface. The issue comes when I attempt to update or write new lines, everything else works great. It appears that I am not getting the lines object loaded correctly. when I check the retVal for the oLines object I am getting "0" returned and I am always getting an error whenever I attempt to perform a 'nGetValue' as I read thru the lines.
Below is my code:
'---------- Login to Sage 100 ----------
strSageUserID = "bpi"
strSagePWD = ""
pCompanyCode = "ABC"
M = Right("00" & CStr(Month(Now())),2)
D = Right("00" & CStr(Day(Now())),2)
Y = CStr(Year(Now()))
LoginDate = Y & M & D
set MAS90_Conn = CreateObject("ADODB.Connection")
set Open_Recordset = CreateObject("ADODB.Recordset")
MAS90_Conn.Open = "DSN=SOTAMAS90; UID=" & strSageUserID & "; PWD=" & strSagePWD & "; Directory=C:\Sage\Sage 100 2019\MAS90; Company=" & pCompanyCode & "; LogFile=\PVXODBC.LOG; CacheSize=8; DirtyReads=1; EnforceNULLDate=1; SERVER=NotTheServer"
Set oScript = CreateObject("ProvideX.Script")
oScript.Init("C:\Sage\Sage 100 2019\MAS90\Home")
Set oSS = oScript.NewObject("SY_Session")
retVal=oSS.nLogon
retVal=oSS.nSetUser(strSageUserID,strSagePWD)
retVal=oSS.nSetCompany(pCompanyCode)
retVAL = oSS.nSetDate("P/O",LoginDate)
retVal = oSS.nSetModule("P/O")
retVal = oSS.nSetProgram(oSS.nLookupTask("PO_ReceiptofInvoice_ui"))
SET oPOInvoiceEntry = oScript.NewObject("PO_Receipt_bus", oSS)
'---------- Set Initial Batch Variables --------
IF oPOInvoiceEntry.nBatchEnabled = 1 Then
BatchNo = ""
oPOInvoiceEntry.nSelectBatch(BatchNo)
End If
'---------- Read thru the records ----------
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Temp\Test\Posted invoicesTest.csv", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
delimiter = """" & "," & """"
arrFields = Split(strLine, delimiter)
iVendorID = arrFields(2)
iGLAccount = arrFields(3)
iInvDate = arrFields(6)
iInvoiceNo = arrFields(7)
iPOReceiptNo = arrFields(7)
iLineDesc = arrFields(8)
iLineAmount = arrFields(9)
iLinePOLine = arrFields(12)
iLinePO = arrFields(13)
iLinePOQty = replace(arrFields(14),"""","")
iInvDateDay = Left(iInvDate,2)
iInvDateMonth = Mid(iInvDate,3,2)
iInvDateYear = Right(iInvDate,4)
FormattedInvDate = iInvDateMonth & "/" & iInvDateDay & "/" & iInvDateYear
'---------- Write the PO Receipt of Invoice Header record -------------
retVal = oPOInvoiceEntry.nSetKeyValue("ReceiptType$","I")
IF retval = 0 Then
ErrorLog retVal, "ERROR ENCOUNTERED CREATING RECEIPT ENTRY. QUITTING.", oPOInvoiceEntry.sLastErrorMsg
WScript.quit
End If
retVal = oPOInvoiceEntry.nGetNextReceiptNo(iPOReceiptNo)
IF retval = 0 Then
ErrorLog retVal, "ERROR ENCOUNTERED GETTING NEXT # ENTRY. QUITTING.", oPOInvoiceEntry.sLastErrorMsg
WScript.quit
End If
retVal = oPOInvoiceEntry.nSetKeyValue("ReceiptNo$",iPOReceiptNo)
retVal = oPOInvoiceEntry.nSetKey()
IF retVal = 0 Then
GoodRecord = 0
ErrorMsg = ErrorMsg & ErrHeader & "Cannot create receipt, Error: " & oPOInvoiceEntry.sLastErrorMsg & Chr(13) & Chr(10)
Else
retVal = oPOInvoiceEntry.nSetValue("ReceiptDate$",FormattedInvDate)
retVal = oPOInvoiceEntry.nSetValue("InvoiceDate$",FormattedInvDate)
retVal = oPOInvoiceEntry.nSetValue("PurchaseOrderNo$",iLinePO)
retVal = oPOInvoiceEntry.nSetValue("InvoiceNo$",iInvoiceNo)
retVal = oPOInvoiceEntry.oLines.nCopyPurchaseOrderLines(iLinePO,0) '---- I have removed this and changed my lines to use the 'nAddLine(), but still did not make a difference.
If retVal <> 1 Then
ErrorMsg = ErrorMsg & ErrHeader & "Cannot copy PO lines, Error: " & oPOInvoiceEntry.oLines.sLastErrorMsg & Chr(13) & Chr(10)
Else
NewReceipt = 0
End If
End If
oPOInvoiceEntry.nWrite() '--- I have removed this and added to see if saving before reading the lines made a difference, it doesn't appear to
'--------- Read and update lines ----------------------
retVal = oPOInvoiceEntry.oLines.nMoveFirst()
do until cBool(oPOInvoiceEntry.oLines.EOF) '---- This always returns '0', which seems to be the source of my problems
retVal = oPOInvoiceEntry.oLines.nGetValue("ItemCode$",i_ItemCode)
RetVal = oPOInvoiceEntry.oLines.nGetValue("LineKey$",i_LineKey)
msgbox i_ItemCode & " - " & i_LineKey
retVal = oPOInvoiceEntry.oLines.nMoveNext()
Loop
PreviousInvNo = iInvoiceNo
Loop
retVal = oPOInvoiceEntry.nWrite()
objFile.Close
oSS.nCleanUp()
retVal = oSS.DropObject()
------------------------------
Dan Isaacson
Bennett Porter
------------------------------