I'm trying to send a manual check to GP with the following code. I'm getting a null reference where indicated ******
I would appreciate any help or recommendations.
Thx.
Imports
Microsoft.VisualBasic
Imports
Microsoft.Dynamics.GP.eConnect.Serialization
Imports
Microsoft.Dynamics.GP.eConnect
Imports
System.IO
Imports
System.Xml.Serialization
Imports
System.Xml
Public
Class
POP
Public
Sub
eConnectRepaySanAntonio(
ByVal
strSARepaymentNumber
As
String
,
ByVal
monSanAntonioRepayment
As
Decimal
)
Dim
mydate
As
DateTime = Now
Dim
strBatchNumber
As
String
=
"eCnctYYYYMMDD"
Dim
check
As
New
taPMManualCheck
With
check
.BACHNUMB = strBatchNumber
.PMNTNMBR = strSARepaymentNumber
.VENDORID =
"SANANTONIO"
.DOCNUMBR = strSARepaymentNumber
.DOCAMNT = monSanAntonioRepayment
.DOCDATE = mydate
.PYENTTYP = 0
'Check
.CHEKBKID =
"CHECKBOOK"
.CREATEDIST = 0
'Manual
End
With
Dim
PMdistItems()
As
taPMDistribution_ItemsTaPMDistribution
Dim
PMdistCash
As
New
taPMDistribution_ItemsTaPMDistribution
With
PMdistCash
.DOCTYPE = 6
'Manual Check
.VCHRNMBR = check.PMNTNMBR
.VENDORID = check.VENDORID
.DISTTYPE = 8
'Misc
.ACTINDX = 1
'Cash-Checking
.CRDTAMNT = check.DOCAMNT
End
With
ReDim
Preserve
PMdistItems(0)
PMdistItems(0) = PMdistCash
Dim
PMdistSA
As
New
taPMDistribution_ItemsTaPMDistribution
With
PMdistSA
.DOCTYPE = 6
'Manual Check
.VCHRNMBR = check.PMNTNMBR
.VENDORID = check.VENDORID
.DISTTYPE = 8
'Misc
.ACTINDX = 120
'San Antonio Repayments Due
.DEBITAMT = check.DOCAMNT
End
With
ReDim
Preserve
PMdistItems(1)
PMdistItems(1) = PMdistSA
Using e
As
New
eConnectMethods
Try
Dim
eConnectDoc
As
New
eConnectType
ReDim
Preserve
eConnectDoc.PMManualCheckType(0)
' **** The following line gives Object reference not set to an instance of an object ****
eConnectDoc.PMManualCheckType(0).taPMManualCheck = check
eConnectDoc.PMManualCheckType(0).taPMDistribution_Items = PMdistItems
'Serialize the request object
Dim
memStream
As
New
MemoryStream()
Dim
serializer
As
New
XmlSerializer(
GetType
(eConnectType))
serializer.Serialize(memStream, eConnectDoc)
memStream.Position = 0
'Create and save a copy of the XML to be sent to GP
Dim
myDoc
As
New
XmlDocument
myDoc.Load(memStream)
'My.Computer.FileSystem.WriteAllText("ManualCheck_" + Trim(strSARepaymentNumber) + ".xml", myDoc.OuterXml.ToString, False)
Dim
sentCheck
As
String
= myDoc.OuterXml
Dim
returnedCheck
As
String
=
""
returnedCheck = e.CreateTransactionEntity(ConnectionString, sentCheck)
Catch
econnecterror
As
eConnectException
Dim
errMsg
As
String
= econnecterror.Message
Catch
ex
As
Exception
Dim
errMsg
As
String
= ex.Message
End
Try
End
Using
End
Sub
End
Class