Sage 100

 View Only
  • 1.  Sage BOI writing a PO Receipt of Invoice

    Posted 10-10-2019 12:58
    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
    ------------------------------


  • 2.  RE: Sage BOI writing a PO Receipt of Invoice

    Posted 10-11-2019 03:02
    After you have set the purchase order number and invoice number, try using retVal = oPOInvoiceEntry.nCopyPurchaseOrderLines(nComplete)
    The parameter is a Boolean to indicate whether you want to receive/invoice complete.

    If the retVal is True/1 then it was successful.
    You can then do a oPOInvoiceEntry.oLines.MoveFirst() and check the retVal for True/1 or check if oPOInvoiceEntry.oLines.BoF and oPOInvoiceEntry.oLines.EoF is not True.
    You can also check oPOInvoiceEntry.oLines.HeaderHasLines, if True/1, then lines exist.
    You can also check oPOInvoiceEntry.oLines.GetRecordCount("Main") which will return the number of records in the "Lines" for the current header if in SET mode which it should be.
    Don't use the header write until after you are done updating the lines.
    From my brief testing, in the actual task with the command window, using CopyPurchaseOrderLines with a True parameter did set the quantity invoiced to the quantity ordered but did not touch the quantity received, just FYI.


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 3.  RE: Sage BOI writing a PO Receipt of Invoice

    Posted 10-11-2019 20:27
    David,

    Thank your for the information.  However, it turns out part of my issues appear to be related to Sage 100 2019.  When I went back to version 2018, I was at least able to have it read the first line.  The issue I am running into now is when it reads the second line of the PO Receipt.  It will read the first line just fine, but then when it gets to the second line I receive an "Error: 0 in Method GETVALUE.  I have my code checking the BoF and EoF and I both of those are returning the correct values (True and False), but not sure why it is erroring out on the reading of the second PO Receipt line?  Any ideas would be appreciated.  Below is a screen shot of the code and the results of the BoF and EoF (of course the BoF is only read prior to the first line).


    ------------------------------
    Dan Isaacson
    Bennett Porter
    ------------------------------



  • 4.  RE: Sage BOI writing a PO Receipt of Invoice

    Posted 10-11-2019 21:00
    First, what value are you passing to the CopyPurchaseOrderLines method, i see you have the variable nComplete which i used as an example but you should be setting either the variable to 0 (don't receive complete) or 1 (receive complete) or just pass either a 0 or a 1 to the parameter.
    Second, i don't see you initializing the variables used in the GetValue methods to the correct data type.
    ProvideX is very picky about numeric and string data types and does not handle the Variant data type which is the default data type for a variable declared in VBScript without a value.
    You should make a habit of first assigning either a blank string or a zero to your variables that are passed to any sage 100 methods where a value is returned in the variable you passed in.
    In other words, before calling a method like GetValue, either at the beginning of the line as a compound statement, add [i_ItemCode="" : ] or on a separate line above the GetValue for the ItemCode, have [i_ItemCode=""]. 
    So either this.
    Or this.


    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 5.  RE: Sage BOI writing a PO Receipt of Invoice

    Posted 10-15-2019 01:45
    David,

    Thank you for the detailed info.  It appears my issue was assigning the blank or zero value, thank you for that type and will be sure to include that in all my future scripts.

    ------------------------------
    Dan Isaacson
    Bennett Porter
    ------------------------------