Sub CreatePATimeSheet()
Dim strReturnDoc As String = ""
Try
Dim intNumberOfLines As Int16 = 0 '0 = 1 line
'declare our eConnect classes
Dim oeConnectType As New Microsoft.Dynamics.GP.eConnect.Serialization.eConnectType
Dim oPATimeSheetsType As New Microsoft.Dynamics.GP.eConnect.Serialization.PATimeSheetsType
'initialize our eConnect wrapper class, documented here:
Dim oeConnectFunctions As New eConnect11Lib.GP11.eConnectFunctions("vmGP11", "TWO")
'create the document header
Dim otaPATimeSheetHdrInsert As New Microsoft.Dynamics.GP.eConnect.Serialization.taPATimeSheetHdrInsert
'populate the header data
'only the minimum fields are required
With otaPATimeSheetHdrInsert
.PATSTYP = 1
.PATSNO = "TS001"
.PADOCDT = "1/1/2017"
.BACHNUMB = String.Format("TS {0:yyMMdd}", Now)
.EMPLOYID = "me"
.PAREPD = 1
.PAREPDT = "1/1/2017"
.CURNCYID = "z-US$"
End With
'assign the header to the master
oPATimeSheetsType.taPATimeSheetHdrInsert = otaPATimeSheetHdrInsert
'create the document details
'simulate looping through an object of some sort
For intCurrentLine As Int16 = 0 To intNumberOfLines
'declare an object for the detail line
Dim otaPATimeSheetLineInsert As New Microsoft.Dynamics.GP.eConnect.Serialization.taPATimeSheetLineInsert_ItemsTaPATimeSheetLineInsert
'populate the detail line
With otaPATimeSheetLineInsert
.PATSTYP = 1
.PATSNO = "TS001"
.EMPLOYID = "BARR0001"
.CURNCYID = "z-US$"
.PADT = "1/1/2017"
.PAPROJNUMBER = "AARONCONTRDD01"
.PACOSTCATID = "WEB DESIGN"
.PAQtyQ = 2
.PAUNITCOST = "10"
.PAUnit_of_Measure = "HOUR"
ReDim Preserve oPATimeSheetsType.taPATimeSheetLineInsert_Items(intCurrentLine)
oPATimeSheetsType.taPATimeSheetLineInsert_Items(intCurrentLine) = otaPATimeSheetLineInsert
End With
Next
ReDim Preserve oeConnectType.PATimeSheetsType(0)
oeConnectType.PATimeSheetsType(0) = oPATimeSheetsType
strReturnDoc = oeConnectFunctions.CreateTransactionEntity(oeConnectType)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub