Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Post multiple batch AR Receipt - error 1

Status
Not open for further replies.

bryan1207

Programmer
Mar 7, 2018
28
PH
I'm trying to add multiple AR Receipt and put the batch number in to a list so that when posting batch it is inside the loop. But upon Posting the batch I've got an error "Cannot post batch XX. Batch status is not Ready To Post or Post In Progress. - Error occurred during posting. No error batch created."

I know there's a problem in this line:

Code:
For Each batch In arr_batch
	ARRECMAC1detail4.Cancel()
	ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(vbNull)     ' Starting Date
	ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("3")       ' Process Command
	ARRECMAC1batch.Process()
	
	ARRECMAC1batchFields.FieldByName("BATCHSTAT").PutWithoutVerification("7")        ' Batch Status
	
	ARRECMAC1batch.Update()
	ARRECMAC1batch.Update()
	
	ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("1")       ' Process Command
	
	ARRECMAC1batch.Process()
	ARPAYMPOST2Fields.FieldByName("BATCHIDFR").PutWithoutVerification(batch)          ' Post Batch From
	
	ARPAYMPOST2Fields.FieldByName("BATCHIDTO").PutWithoutVerification(batch)          ' Post Batch To
	
	ARPAYMPOST2.Process()
	ARRECMAC1batch.Read()
	ARRECMAC1detail4.Cancel()
	ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", 1)
	
	ARRECMAC1detail2Fields.FieldByName("CNTSEQ").PutWithoutVerification("-99999")    ' Sequence No.
	
	ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", -1)
	ARRECMAC1detail2.Fetch()
	ARRECMAC1headerFields.FieldByName("CNTITEM").PutWithoutVerification("-9999999")   ' Entry Number
	ARRECMAC1header.Browse("", 1)
	ARRECMAC1header.Fetch()
	ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", 1)
	
	ARRECMAC1detail2Fields.FieldByName("CNTSEQ").PutWithoutVerification("-99999")    ' Sequence No.
	
	ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", -1)
	ARRECMAC1detail2.Fetch()
Next

Here's the full code:

Code:
Dim newDs As DataSet
newDs = New DataSet
newDs = drDetails

Dim oInvoiceNo As String = ""

Dim ctr As Integer = 0

For Each oDr As DataRow In newDs.Tables(0).Rows
	ARRECMAC1batch.RecordClear()
	
	ARRECMAC1batchFields.FieldByName("CODEPYMTYP").PutWithoutVerification("CA")      ' Batch Type
	
	ARRECMAC1batchFields.FieldByName("CNTBTCH").PutWithoutVerification("0")          ' Batch Number
	
	ARRECMAC1batch.RecordCreate(1)
	
	ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("2")       ' Process Command
	
	ARRECMAC1batch.Process()
	ARRECMAC1detail4.Cancel()
	temp = ARRECMAC1header.Exists
	ARRECMAC1header.RecordCreate(2)
	ARRECMAC1detail4.Cancel()
	temp = ARRECMAC1header.Exists
	ARRECMAC1batchFields.FieldByName("BATCHDESC").PutWithoutVerification("Astute Import - " & Date.Now)       ' Description
	
'Get Batch number 
	_newBatch = ARRECMAC1batchFields.FieldByName("CNTBTCH").Value
	arr_batch.Add(_newBatch)
	
	ARRECMAC1batch.Update()
'ARRECMAC1headerFields.FieldByName("TEXTRMIT").Value = "BB"                        ' Entry Description
	
	ARRECMAC1headerFields.FieldByName("IDCUST").Value = oDr("Card ID")                      ' Customer Number
	
	ARRECMAC1detail1.Cancel()
	ARRECMAC1headerFields.FieldByName("PROCESSCMD").PutWithoutVerification("0")      ' Process Command Code
	ARRECMAC1header.Process()
	ARRECMAC1detail4.Cancel()
	
	ARRECMAC1detail4Fields.FieldByName("PAYMTYPE").Value = "CA"                       ' Batch Type
'ARRECMAC1detail4Fields.FieldByName("CNTBTCH").Value = "10"                        ' Batch Number
	ARRECMAC1detail4Fields.FieldByName("CNTITEM").Value = "0"                         ' Entry Number
	ARRECMAC1detail4Fields.FieldByName("IDCUST").Value = oDr("Card ID")                     ' ID Customer
	ARRECMAC1detail4Fields.FieldByName("AMTRMIT").Value = "0.000"                     ' Receipt Amount
	ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(DateSerial(100, 1, 1))    ' Starting Date
	ARRECMAC1detail4Fields.FieldByName("PROTYPE").PutWithoutVerification("1")        ' Process Type
	
	ARRECMAC1detail4.Process()
	
	ARRECMAC1detail4Fields.FieldByName("STDOCSTR").PutWithoutVerification("")        ' Starting Doc. Number
	ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(vbNull)     ' Starting Date
	ARRECMAC1detail4Fields.FieldByName("STDOCAMT").PutWithoutVerification("-999999999999999.999")   ' Starting Amount
	ARRECMAC1detail1.RecordClear()
	ARRECMAC1detail1.RecordCreate(0)
	
	ARRECMAC1detail1Fields.FieldByName("IDINVC").Value = oDr("Invoice No")                        ' Document Number
	ARRECMAC1detail1Fields.FieldByName("CNTPAYM").Value = "1"                         ' Payment Number
	ARRECMAC1detail1Fields.FieldByName("AMTPAYM").Value = oDr("Amount Applied")                        ' Document Number
	
	ARRECMAC1detail1.Insert()
	
	ARRECMAC1detail1Fields.FieldByName("CNTLINE").PutWithoutVerification("-1")       ' Line Number
	
	ARRECMAC1detail1.Read()
	ARRECMAC1headerFields.FieldByName("AMTRMIT").Value = oDr("Amount Applied")                   ' Bank Receipt Amount
	
	Dim _date As String
	_date = oDr("Receipt Date").ToString.Replace(".", "/")
	Dim adate As DateTime = DateTime.ParseExact(_date, "dd/MM/yyyy", CultureInfo.InvariantCulture)
	Dim reformatted As String = adate.ToString("yyyyMMdd", CultureInfo.InvariantCulture)
	
	ARRECMAC1headerFields.FieldByName("DATERMIT").Value = adate    ' Receipt Date/Adjustment Date
	ARRECMAC1headerFields.FieldByName("DATEBUS").Value = Date.Today     ' Posting Date
	
	ARRECMAC1detail5Fields.FieldByName("OPTFIELD").PutWithoutVerification("JOBCODE")   ' Optional Field
	ARRECMAC1detail5.Read()
	ARRECMAC1detail5Fields.FieldByName("SWSET").Value = "1"                           ' Value Set  
	ARRECMAC1detail5.Update()
	
	ARRECMAC1detail5Fields.FieldByName("OPTFIELD").PutWithoutVerification("RECHCLIENT")   ' Optional Field 
	ARRECMAC1detail5.Read()
	ARRECMAC1detail5Fields.FieldByName("SWSET").Value = "1"                           ' Value Set  
	ARRECMAC1detail5.Update()
	
	ARRECMAC1detail5.Read()
	ARRECMAC1header.Insert()
	ARRECMAC1detail4.Cancel()
	ARRECMAC1detail4Fields.FieldByName("PAYMTYPE").Value = "CA"                       ' Batch Type
	
'ARRECMAC1detail4Fields.FieldByName("CNTBTCH").Value = "10"                        ' Batch Number
	ARRECMAC1detail4Fields.FieldByName("CNTITEM").Value = "1"                         ' Entry Number
	ARRECMAC1detail4Fields.FieldByName("IDCUST").Value = oDr("Card ID")                     ' ID Customer
	ARRECMAC1detail4Fields.FieldByName("AMTRMIT").Value = oDr("Amount Applied")                  ' Receipt Amount
	ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(DateSerial(100, 1, 1))    ' Starting Date
	ARRECMAC1detail4Fields.FieldByName("PROTYPE").PutWithoutVerification("1")        ' Process Type
	
	ARRECMAC1detail4.Process()
	
	ARRECMAC1detail4Fields.FieldByName("STDOCSTR").PutWithoutVerification("")        ' Starting Doc. Number
	ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(vbNull)     ' Starting Date
	ARRECMAC1detail4Fields.FieldByName("STDOCAMT").PutWithoutVerification("-999999999999999.999")   ' Starting Amount
	ARRECMAC1batch.Read()
	ARRECMAC1headerFields.FieldByName("CNTITEM").PutWithoutVerification("0")         ' Entry Number
	ARRECMAC1header.RecordCreate(2)
	
	ctr += 1
Next

Catch ex As Exception
isErrHeader = True
line_no = 0
sError = Err.Description
fHandleSageErrors(sError)
sError = "ERR~~<Document Number - " & _newBatch & "> " & sError
fLogIt("[Err]-fCreateARReceiptTransaction-<Document Number - " & _newBatch & "> Error: " & sError)

For Each batch In arr_batch
	ARRECMAC1batchFields.FieldByName("CNTBTCH").Value = batch                     ' Batch Number
	ARRECMAC1batch.Read()
	ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("2")      ' Process Command 
	ARRECMAC1batch.Process()
	
	ARRECMAC1batchFields.FieldByName("BATCHSTAT").Value = "4"                         ' Batch Status 4 = Delete
	ARRECMAC1batch.Update()
	
	ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("0")      ' Process Command 
	ARRECMAC1batch.Process()
Next

Return False
End Try

'Post Command
'Dim batchNumber As String = ""
'batchNumber = ARRECMAC1headerFields.FieldByName("CNTBTCH").Value

For Each batch In arr_batch
	ARRECMAC1detail4.Cancel()
	ARRECMAC1detail4Fields.FieldByName("STDOCDTE").PutWithoutVerification(vbNull)     ' Starting Date
	ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("3")       ' Process Command
	ARRECMAC1batch.Process()
	
	ARRECMAC1batchFields.FieldByName("BATCHSTAT").PutWithoutVerification("7")        ' Batch Status
	
	ARRECMAC1batch.Update()
	ARRECMAC1batch.Update()
	
	ARRECMAC1batchFields.FieldByName("PROCESSCMD").PutWithoutVerification("1")       ' Process Command
	
	ARRECMAC1batch.Process()
	ARPAYMPOST2Fields.FieldByName("BATCHIDFR").PutWithoutVerification(batch)          ' Post Batch From
	
	ARPAYMPOST2Fields.FieldByName("BATCHIDTO").PutWithoutVerification(batch)          ' Post Batch To
	
	ARPAYMPOST2.Process()
	ARRECMAC1batch.Read()
	ARRECMAC1detail4.Cancel()
	ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", 1)
	
	ARRECMAC1detail2Fields.FieldByName("CNTSEQ").PutWithoutVerification("-99999")    ' Sequence No.
	
	ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", -1)
	ARRECMAC1detail2.Fetch()
	ARRECMAC1headerFields.FieldByName("CNTITEM").PutWithoutVerification("-9999999")   ' Entry Number
	ARRECMAC1header.Browse("", 1)
	ARRECMAC1header.Fetch()
	ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", 1)
	
	ARRECMAC1detail2Fields.FieldByName("CNTSEQ").PutWithoutVerification("-99999")    ' Sequence No.
	
	ARRECMAC1detail2.Browse("(CODTRXTYPE = 81)", -1)
	ARRECMAC1detail2.Fetch()
Next
 
1. NEVER delete error batches
2. All your "temp =" lines are junk code
3. Use the ARPYPT view to post batches


Sage 300 Whisperer
 
Here's a clip from some object code that I have to handle batches (thus some of the variables are defined elsewhere). Do future you a favour and give your variables meaningful names and clean up the code.

Code:
    With ReceiptBatch
        .Fields("PROCESSCMD").PutWithoutVerification ("3")    ' Process Command
        .Process
        .Fields("BATCHSTAT").Value = "7"                      ' Batch Status
        .Update
        .Fields("PROCESSCMD").PutWithoutVerification ("1")    ' Process Command
        .Process
    End With

    Dim ARReceiptPost As AccpacCOMAPI.AccpacView
    fDBLink.OpenView "AR0049", ARReceiptPost

    ARReceiptPost.Fields("BATCHIDFR").PutWithoutVerification BatchNumber
    ARReceiptPost.Fields("BATCHIDTO").PutWithoutVerification BatchNumber

    ARReceiptPost.Process
 
What is "ARPYPT" means?

@DjangMan, your code is just similar to mine.
 
Here's my code prior to For each Loop.

So I guess the AR0049 is already declared for post.

Code:
 Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
            mDBLinkCmpRW = sSageSession.OpenDBLink(AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_COMPANY, AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE)
            Dim mDBLinkSysRW As AccpacCOMAPI.AccpacDBLink
            mDBLinkSysRW = sSageSession.OpenDBLink(AccpacCOMAPI.tagDBLinkTypeEnum.DBLINK_SYSTEM, AccpacCOMAPI.tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE)

            Dim temp As Boolean
            Dim ARRECMAC1batch As AccpacCOMAPI.AccpacView
            Dim ARRECMAC1batchFields As AccpacCOMAPI.AccpacViewFields
            mDBLinkCmpRW.OpenView("AR0041", ARRECMAC1batch)
            ARRECMAC1batchFields = ARRECMAC1batch.Fields

            Dim ARRECMAC1header As AccpacCOMAPI.AccpacView
            Dim ARRECMAC1headerFields As AccpacCOMAPI.AccpacViewFields
            mDBLinkCmpRW.OpenView("AR0042", ARRECMAC1header)
            ARRECMAC1headerFields = ARRECMAC1header.Fields

            Dim ARRECMAC1detail1 As AccpacCOMAPI.AccpacView
            Dim ARRECMAC1detail1Fields As AccpacCOMAPI.AccpacViewFields
            mDBLinkCmpRW.OpenView("AR0044", ARRECMAC1detail1)
            ARRECMAC1detail1Fields = ARRECMAC1detail1.Fields

            Dim ARRECMAC1detail2 As AccpacCOMAPI.AccpacView
            Dim ARRECMAC1detail2Fields As AccpacCOMAPI.AccpacViewFields
            mDBLinkCmpRW.OpenView("AR0045", ARRECMAC1detail2)
            ARRECMAC1detail2Fields = ARRECMAC1detail2.Fields

            Dim ARRECMAC1detail3 As AccpacCOMAPI.AccpacView
            Dim ARRECMAC1detail3Fields As AccpacCOMAPI.AccpacViewFields
            mDBLinkCmpRW.OpenView("AR0043", ARRECMAC1detail3)
            ARRECMAC1detail3Fields = ARRECMAC1detail3.Fields

            Dim ARRECMAC1detail4 As AccpacCOMAPI.AccpacView
            Dim ARRECMAC1detail4Fields As AccpacCOMAPI.AccpacViewFields
            mDBLinkCmpRW.OpenView("AR0061", ARRECMAC1detail4)
            ARRECMAC1detail4Fields = ARRECMAC1detail4.Fields

            Dim ARRECMAC1detail5 As AccpacCOMAPI.AccpacView
            Dim ARRECMAC1detail5Fields As AccpacCOMAPI.AccpacViewFields
            mDBLinkCmpRW.OpenView("AR0406", ARRECMAC1detail5)
            ARRECMAC1detail5Fields = ARRECMAC1detail5.Fields

            Dim ARRECMAC1detail6 As AccpacCOMAPI.AccpacView
            Dim ARRECMAC1detail6Fields As AccpacCOMAPI.AccpacViewFields
            mDBLinkCmpRW.OpenView("AR0170", ARRECMAC1detail6)
            ARRECMAC1detail6Fields = ARRECMAC1detail6.Fields

            ARRECMAC1batch.Compose(New AccpacCOMAPI.AccpacView() {ARRECMAC1header})

            ARRECMAC1header.Compose(New AccpacCOMAPI.AccpacView() {ARRECMAC1batch, ARRECMAC1detail3, ARRECMAC1detail1, ARRECMAC1detail5, ARRECMAC1detail6})

            ARRECMAC1detail1.Compose(New AccpacCOMAPI.AccpacView() {ARRECMAC1header, ARRECMAC1detail2, ARRECMAC1detail4})

            ARRECMAC1detail2.Compose(New AccpacCOMAPI.AccpacView() {ARRECMAC1detail1})

            ARRECMAC1detail3.Compose(New AccpacCOMAPI.AccpacView() {ARRECMAC1header})

            ARRECMAC1detail4.Compose(New AccpacCOMAPI.AccpacView() {ARRECMAC1batch, ARRECMAC1header, ARRECMAC1detail3, ARRECMAC1detail1, ARRECMAC1detail2})

            ARRECMAC1detail5.Compose(New AccpacCOMAPI.AccpacView() {ARRECMAC1header})

            ARRECMAC1detail6.Compose(New AccpacCOMAPI.AccpacView() {ARRECMAC1header})


            Dim ARPAYMPOST2 As AccpacCOMAPI.AccpacView
            Dim ARPAYMPOST2Fields As AccpacCOMAPI.AccpacViewFields
            mDBLinkCmpRW.OpenView("AR0049", ARPAYMPOST2)
            ARPAYMPOST2Fields = ARPAYMPOST2.Fields

            Dim _newBatch As String = vbNullString
            Dim batchNumber As String = ""

            Dim arr_batch As New List(Of String)()
 
I just used your code and add maybe two lines of code.

Code:
[ignore]            Dim ReceiptBatch As AccpacCOMAPI.AccpacView
            Dim ReceiptBatchFields As AccpacCOMAPI.AccpacViewFields
            mDBLinkCmpRW.OpenView("AR0041", ReceiptBatch)
            ReceiptBatchFields = ReceiptBatch.Fields
             
            For Each batch In arr_batch 
                With ReceiptBatch
                    .Fields.FieldByName("CODEPYMTYP").Value = "CA"
                    .Fields.FieldByName("CNTBTCH").Value = batch
                    .Read()
                    .Fields.FieldByName("PROCESSCMD").PutWithoutVerification("3")    ' Process Command
                    .Process()
                    .Fields.FieldByName("BATCHSTAT").Value = "7"                      ' Batch Status
                    .Update()
                    .Fields.FieldByName("PROCESSCMD").PutWithoutVerification("1")    ' Process Command
                    .Process()
                End With

                Dim ARReceiptPost As AccpacCOMAPI.AccpacView
                mDBLinkCmpRW.OpenView("AR0049", ARReceiptPost)

                ARReceiptPost.Fields.FieldByName("BATCHIDFR").PutWithoutVerification(batch)
                ARReceiptPost.Fields.FieldByName("BATCHIDTO").PutWithoutVerification(batch)

                ARReceiptPost.Process()
                 
            Next[/ignore]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top