BOI - AP Manual Check Entry creating an Invoice on the fly

SOLVED

I am writing a service that monitors a directory for files downloaded from a web service called Concur.  The employees submit expense reports in Concur, the managers approve them and then the employee is reimbursed by Concur.  To account for the expense payments the customer wants to bring in the transactions as wire transfer manual checks and associate the expenses with the employee (vendor).

I have shortened my code to make it more legible including the directory monitoring and file manipulation.  What is here is the BOI code from a function call that returns a boolean (true - data imported or false - data not imported).  I have also modified the code to write the Job, CostCode, and CostType values as I kept getting "AccountKey is not a valid IO field" which what I really want to use since there will be no Job associated with the expenses.

At this point, no data is being saved.  I am receiving a retVal of 2 for both of the nAddLine() methods but when I try to nWrite() the distribution line I get: "The record is not in an editble state"

Using oInputFile As New StreamReader(dra)
Try
' aDistLine(row, column) is an array with the counters and data from the input file
' column 1 is the row number in the file
' column 2 is the Expense Report number in the file
' column 3 is the Expense Report row number
' column 4 is the number of distributions in the Expense Report
' column 5 is the pipe delimited data

' Initialize MAS connection
oScript.Init(masPath)
oSS = oScript.NewObject("SY_SESSION")
If Not (CBool(oSS.nLogon())) Then
retVal = CBool(oSS.nSetUser(masUser, masPW))
End If
retVal = oSS.nSetCompany(masCompany)

' Start Manual Check Entry
If Not SetSession(oSS, "A/P", "AP_ManualCheck_Ui") Then
Return False
End If

' Start Looping through data
For i = 1 To iRecordCount
aInputData = aDistLine(i, 5).Split("|")

' First ER line - Create Manual Check Header
If aDistLine(i, 3) = 1 Then
oMCObj = oScript.NewObject("AP_ManualCheck_bus", oSS)

' Create batch only on the first line in the file
If oMCObj.nBatchEnabled = 1 And aDistLine(i, 1) = 1 Then ' New Batch
sBatchComment = "Concur Import: " + aInputData(1) + " " + aInputData(2)
retVal = oMCObj.nSelectNewBatch(sBatchNo, sPrivate, sBatchComment)
End If

' Get next transfer number
oAPOptionsObj = oScript.NewObject("AP_Options_Svc", oSS)
retVal = oAPOptionsObj.nGetNextSequenceNoForWireTransferXfer(sCheckNo)
oAPOptionsObj.DropObject()
oAPOptionsObj = Nothing

' Create Manual Check Header Key
retVal = oMCObj.nSetKeyValue("BankCode$", sBankCode)
retVal = oMCObj.nSetKeyValue("CheckType$", "W")
sCheckNo = "W" + sCheckNo
retVal = oMCObj.nSetKeyValue("CheckNo$", sCheckNo)
retVal = oMCObj.nSetKey()
'==============================================================
' Returns 2 - New
'==============================================================

' Create Manual Check Header Fields
'retVal = oMCObj.CreateWireTransfer()
retVal = oMCObj.nSetValue("BatchNo$", sBatchNo)
retVal = oMCObj.nSetValue("CheckDate$", Replace(aInputData(23), "-", ""))
retVal = oMCObj.nSetValue("CheckAmt", CDbl(aInputData(31)))
retVal = oMCObj.nSetValue("APDivisionNo$", "00")
retVal = oMCObj.nSetValue("VendorNo$", aInputData(4))
retVal = oMCObj.nSetValue("Comment$", aInputData(26))
retVal = oMCObj.nSetValue("WireTransferNo$", aInputData(18))

' Create Invoice Header Line
retVal = oMCObj.nAddLine()

' Create Invoice Header Fields
'retVal = oMCObj.oLines.nSetValue("InvoiceType$", "A")
'sInvoiceNo = "Concur-" + aInputData(19)
'retVal = oMCObj.oLines.nSetValue("InvoiceNo$", sInvoiceNo)
'retVal = oMCObj.oLines.nSetValue("InvoiceDate$", Replace(aInputData(23), "-", ""))
'retVal = oMCObj.oLines.nSetValue("TaxSchedule$", "NONTAX")
'retVal = oMCObj.oLines.nSetValue("InvoiceComment$", aInputData(26))
'retVal = oMCObj.oLines.nSetValue("InvoiceAmt", CDbl(aInputData(31)))
End If

' Create distribution line for each line in the Expense Report
If aDistLine(i, 3) <= aDistLine(i, 4) Then

' Create distribution Key
retVal = oMCObj.oLines.nAddLine()

' Create distribution fields
'sAccount = aInputData(166) + aInputData(201) + aInputData(203) + aInputData(200) + aInputData(202)
'retVal = oMCObj.oLines.oDistribution.nSetValue("AccountKey$", sAccount)
'==============================================================
' Returns 0 - AccountKey is not a valid IO field
'==============================================================
retVal = oMCObj.oLines.oDistribution.nSetValue("Job$", aInputData(63))
retVal = oMCObj.oLines.oDistribution.nSetValue("CostCode$", aInputData(64))
retVal = oMCObj.oLines.oDistribution.nSetValue("CostType$", aInputData(65))
retVal = oMCObj.oLines.oDistribution.nSetValue("CommentText$", aInputData(62))
'==============================================================
' Returns 0 - CommentText is not a valid IO field
'==============================================================
retVal = oMCObj.oLines.oDistribution.nSetValue("DistributionAmt", CDbl(aInputData(168)))

' Close the distribution Line
retVal = oMCObj.oLines.oDistribution.nWrite()
'==============================================================
' Returns 0 - The record is not in an editable state
'==============================================================
retVal = oMCObj.oLines.oDistribution.nCommitRow()

End If

' Close Invoice and Manual Check on the last Expense Report line
If aDistLine(i, 3) = aDistLine(i, 4) Then

' Close Invoice Line
retVal = oMCObj.oLines.nWrite()
retVal = oMCObj.oLines.nCommitRow()

' Close Manual Check
retVal = oMCObj.nWrite()

End If

Next

Catch ex As Exception
Log("BOI Scripting exception Error: " + ex.Message, 0)
Return False
End Try

Log("BOI Closed", 1)
Return True
End Using  

  • 0
    verified answer

    Here is a simple example of creating a manual check with invoice distribution in ProvideX syntax.  Note the  handle to invoice distribution is oMC'Lines'Lines.

    oMC = NEW("AP_ManualCheck_bus", %sys_ss)

    ! set manual check header fields

    retVal = oMC'SetKeyValue("BankCode$","D")

    retval = oMC'SetKeyValue("CheckType$", "W")

    retval = oMC'SetKeyValue("CheckNo$", "W00002")

    retVal = oMC'SetKey()

    retVal = oMC'SetValue("APDivisionNo$","01")

    retVal = oMC'SetValue("VendorNo$","AIRWAY")

    retval = oMC'SetValue("CheckDate$","20131230")

    retval = oMC'SetValue("CheckAmt", 100)

    ! add manual check line

    retVal = oMC'Lines'AddLine()

    retVal = oMC'Lines'SetValue("InvoiceNo$","1234567")

    retVal = oMC'Lines'SetValue("InvoiceAmt", 100)

    ! add invoice distribution line

    retVal = oMC'Lines'Lines'AddLine()

    retVal = oMC'Lines'Lines'SetValue("AccountKey$", "555000300")

    retVal = oMC'Lines'Lines'SetValue("DistributionAmt", 100)

    ! write invoice distribution

    retVal = oMC'Lines'Lines'Write()

    ! write manual check detail

    retVal = oMC'Lines'Write()

    ! write manual check header

    retVal = oMC'Write()

    drop object oMCEntry

  • 0 in reply to Natasha Chang

    Thank you  very much for your reply.  I had modeled my code after lot/serial distribution because the button on the MC invoice line has a comment of Distribution.  This solved my probllem.  All I have to do now is to figure out how to print the batch to paperless office and post the batch.  If I get stuck, I'll create a new post.

  • 0 in reply to johnwwiles

    By the way, I'm stuck.  I seems that the service does not release the batch so that I can print it.  As long as the service is running the batch shows 'In Use' even after I close and drop all business objects except the oSS.  Any thoughts on how I can release the batch without stopping the service?

  • 0 in reply to johnwwiles

    I think I may have stumbled across the issue.  I do drop the oSS but pvxcom.exe continues to run as a process until the service stops.  Another post said that I have to encapsulate the BOI calls within a separate class.  I will try that and update this post afterward.