warrickvdb
Programmer
I am trying to create an invoice through DotNet. I copied the code from a Macro that was run through AccPac, and then made it DotNet 'friendly' (I have to use the enum's as the object wont accept string values).
The error occurs when I try to assign the IDITEM to the detail object.
Error:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in aplaccpac.dll
Additional information: View call failed
Code:
Public Class clsAccPac
Enum Detail_1
CNTBTCH = 0
CNTITEM = 1
CNTLINE = 2
IDITEM = 4
AMTPRIC = 11
End Enum
Enum Detail_2
CNTBTCH = 0
CNTITEM = 1
CNTPAYM = 2
End Enum
Enum Header_1
CNTBTCH = 0
CNTITEM = 1
IDCUST = 2
IDINVC = 3
PROCESSCMD = 108
End Enum
Public Function createInvoice() As Integer
Dim intBatchNumber As Integer = 570
Dim session As New ACCPACXAPILib.xapiSession
session.Open("ADMIN", "ADMIN", "RMICON", Now.Today, 0)
Dim ARINVOICE3batch As ACCPACXAPILib.xapiView
Dim ARINVOICE3batchFields As ACCPACXAPILib.xapiFields
ARINVOICE3batch = session.OpenView("AR0031", "AR"
ARINVOICE3batchFields = ARINVOICE3batch.Fields
Dim ARINVOICE3header As ACCPACXAPILib.xapiView
Dim ARINVOICE3headerFields As ACCPACXAPILib.xapiFields
ARINVOICE3header = session.OpenView("AR0032", "AR"
ARINVOICE3headerFields = ARINVOICE3header.Fields
Dim ARINVOICE3detail1 As ACCPACXAPILib.xapiView
Dim ARINVOICE3detail1Fields As ACCPACXAPILib.xapiFields
ARINVOICE3detail1 = session.OpenView("AR0033", "AR"
ARINVOICE3detail1Fields = ARINVOICE3detail1.Fields
Dim ARINVOICE3detail2 As ACCPACXAPILib.xapiView
Dim ARINVOICE3detail2Fields As ACCPACXAPILib.xapiFields
ARINVOICE3detail2 = session.OpenView("AR0034", "AR"
ARINVOICE3detail2Fields = ARINVOICE3detail2.Fields
ARINVOICE3batch.Compose((ARINVOICE3header))
Dim arr(2) As Object
arr(0) = ARINVOICE3batch
arr(1) = ARINVOICE3detail1
arr(2) = ARINVOICE3detail2
ARINVOICE3header.Compose(arr)
Dim arr2(1) As Object
arr(0) = ARINVOICE3header
arr(1) = ARINVOICE3batch
ARINVOICE3detail1.Compose(arr2)
ARINVOICE3detail2.Compose((ARINVOICE3header))
ARINVOICE3batch.Init()
ARINVOICE3header.Init()
ARINVOICE3headerFields.Field(Header_1.IDCUST).Value = "1000003"
ARINVOICE3headerFields.Field(Header_1.IDINVC).Value = "INV0000000000000000006"
ARINVOICE3headerFields.Field(Header_1.PROCESSCMD).PutWithoutVerification("3"
ARINVOICE3detail1.Init()
ARINVOICE3detail1Fields.Field(Detail_1.IDITEM).Value = "ASSOC-CPT "
ARINVOICE3detail1Fields.Field(Detail_1.AMTPRIC).Value = "1200.000000"
ARINVOICE3detail2.Init()
ARINVOICE3detail2Fields.Field(Detail_2.CNTPAYM).PutWithoutVerification("-1"
ARINVOICE3detail1.Insert()
ARINVOICE3header.Insert()
ARINVOICE3header.Cancel()
End Function
End Class
The error occurs when I try to assign the IDITEM to the detail object.
Error:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in aplaccpac.dll
Additional information: View call failed
Code:
Public Class clsAccPac
Enum Detail_1
CNTBTCH = 0
CNTITEM = 1
CNTLINE = 2
IDITEM = 4
AMTPRIC = 11
End Enum
Enum Detail_2
CNTBTCH = 0
CNTITEM = 1
CNTPAYM = 2
End Enum
Enum Header_1
CNTBTCH = 0
CNTITEM = 1
IDCUST = 2
IDINVC = 3
PROCESSCMD = 108
End Enum
Public Function createInvoice() As Integer
Dim intBatchNumber As Integer = 570
Dim session As New ACCPACXAPILib.xapiSession
session.Open("ADMIN", "ADMIN", "RMICON", Now.Today, 0)
Dim ARINVOICE3batch As ACCPACXAPILib.xapiView
Dim ARINVOICE3batchFields As ACCPACXAPILib.xapiFields
ARINVOICE3batch = session.OpenView("AR0031", "AR"
ARINVOICE3batchFields = ARINVOICE3batch.Fields
Dim ARINVOICE3header As ACCPACXAPILib.xapiView
Dim ARINVOICE3headerFields As ACCPACXAPILib.xapiFields
ARINVOICE3header = session.OpenView("AR0032", "AR"
ARINVOICE3headerFields = ARINVOICE3header.Fields
Dim ARINVOICE3detail1 As ACCPACXAPILib.xapiView
Dim ARINVOICE3detail1Fields As ACCPACXAPILib.xapiFields
ARINVOICE3detail1 = session.OpenView("AR0033", "AR"
ARINVOICE3detail1Fields = ARINVOICE3detail1.Fields
Dim ARINVOICE3detail2 As ACCPACXAPILib.xapiView
Dim ARINVOICE3detail2Fields As ACCPACXAPILib.xapiFields
ARINVOICE3detail2 = session.OpenView("AR0034", "AR"
ARINVOICE3detail2Fields = ARINVOICE3detail2.Fields
ARINVOICE3batch.Compose((ARINVOICE3header))
Dim arr(2) As Object
arr(0) = ARINVOICE3batch
arr(1) = ARINVOICE3detail1
arr(2) = ARINVOICE3detail2
ARINVOICE3header.Compose(arr)
Dim arr2(1) As Object
arr(0) = ARINVOICE3header
arr(1) = ARINVOICE3batch
ARINVOICE3detail1.Compose(arr2)
ARINVOICE3detail2.Compose((ARINVOICE3header))
ARINVOICE3batch.Init()
ARINVOICE3header.Init()
ARINVOICE3headerFields.Field(Header_1.IDCUST).Value = "1000003"
ARINVOICE3headerFields.Field(Header_1.IDINVC).Value = "INV0000000000000000006"
ARINVOICE3headerFields.Field(Header_1.PROCESSCMD).PutWithoutVerification("3"
ARINVOICE3detail1.Init()
ARINVOICE3detail1Fields.Field(Detail_1.IDITEM).Value = "ASSOC-CPT "
ARINVOICE3detail1Fields.Field(Detail_1.AMTPRIC).Value = "1200.000000"
ARINVOICE3detail2.Init()
ARINVOICE3detail2Fields.Field(Detail_2.CNTPAYM).PutWithoutVerification("-1"
ARINVOICE3detail1.Insert()
ARINVOICE3header.Insert()
ARINVOICE3header.Cancel()
End Function
End Class