web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Using e-connect to create a Purchase order

(0) ShareShare
ReportReport
Posted on by 75

Hello all. I'm a newbie and hoping for a little help. Using the e-connect examples I've got this far and cannot get any further. i'm simply trying to piece together a simple PO import. We're on GP 2013 R2 using .NET C#.  I think the issue is adding the line to the PO, but i'm not certain. ANY and ALL help is much appreciated!!!!  here  is our code:

_______________________________________________________________________

Imports System
Imports System.Xml
Imports System.Xml.Serialization
Imports System.IO
Imports System.Text
Imports Microsoft.Dynamics.GP.eConnect
Imports Microsoft.Dynamics.GP.eConnect.Serialization

Module Module1

Sub Main()
'String variable to hold the xml document
Dim sCustomerDocument As String
'String variable to hold the SQL connection string
Dim sConnectionString As String

'Use the eConnect methods to send the xml document to GP
Using e As New eConnectMethods
'Begin error trapping
Try
'Run the SerializeCustomerObject sub (see below) to create the XML document called Customer.xml
SerializeCustomerObject("Customer.xml")

'Load the customer XML document into an XML document object
Dim xmldoc As New Xml.XmlDocument
xmldoc.Load("Customer.xml")

'Use the XML Document to create a string
sCustomerDocument = xmldoc.OuterXml

'Create a connection string to your Microsoft Dynamics GP Datebase
'Replace data source and inital catalog values to use your server and company database
sConnectionString = "data source=GP-2013;initial catalog=TWO;integrated security=SSPI;persist security info=False;packet size=4096"

'From the eConnect namespace. the CreateEntity function creates the new customer in Microsoft Dynamics GP.
e.CreateEntity(sConnectionString, sCustomerDocument)

'Catch any errors
Catch exc As eConnectException
Console.Write("An eConnect error occured")
Console.Write(exc.ToString)
Catch ex As System.Exception
Console.Write(ex.ToString)
Finally
'Use the dispose method to release the resources of
'eConnectMethods object
e.Dispose()
End Try
End Using

End Sub

Public Sub SerializeCustomerObject(ByVal filename As String)
'This sub routine utilizes the eConnect.Serialization namespace to create the xml document

'Use the System.XML class which will serialize the xml document
Dim serializer As New XmlSerializer(GetType(eConnectType))
'From the eConnect.Serialization Namespace. The eConnectType class represents the root of the eConnect document and holds
'different eConnect document collection objects.
Dim eConnect As New eConnectType
'From the eConnect.Serialization Namespace. The taUpdateCreateCustomerRcd class represents the eConnect node used to update or create customers.
Dim otaPoHdr As New taPoHdr

'From the eConnect.Serialization Namespace. the RMCustomerMaterType contains the schema representing the CustomerMaster Document colleciton.
Dim oPOPTransactionType As New POPTransactionType
'Begin error trapping.
Try
'Populate the taPopRcptHdrInsert XML node with customer data
With otaPoHdr

'.POTYPE = 1
.PONUMBER = "PO3333"
.VENDORID = "FABRIKAM0001"
.DOCDATE = "04152017"
.ALLOWSOCMTS = 1
.ALLOWSOCMTSSpecified = 1
.VADCDPAD = "PRIMARY"
.UpdateIfExists = 1

'.CURNCYID = "Z-US$"

.TAXSCHID = "COMPANYPUR"
End With

'assign the header to the master
oPOPTransactionType.taPoHdr = otaPoHdr

Dim intCurrentLine As Int16 = 0

'declare an object for the detail line
Dim otaPoline As New taPoLine_ItemsTaPoLine
With otaPoline
.PONUMBER = "PO3333"
.VENDORID = "FABRIKAM0001"
.ITEMNMBR = "3-A2440A"
.LOCNCODE = "131G"
.VNDITNUM = "131G"
.QUANTITY = "3.000"
.QUANTITYSpecified = 1
.ITEMDESC = "tst"
.UNITCOST = "100.00"
.UNITCOSTSpecified = 1
.UOFM = "EA"
'.QTYCANCE = "0.000"

End With

'Populate the RMCustomerMasterType schema with the taUpdateCreateCustomerRcd XML node object
'oPOPTransactionType.taPoHdr = otaPoHdr
ReDim Preserve oPOPTransactionType.taPoLine_Items(intCurrentLine)
oPOPTransactionType.taPoLine_Items(intCurrentLine) = otaPoline

intCurrentLine += 1

'Populate the eConnect XML document object with the RMCustomerMasterType schema object
ReDim Preserve eConnect.POPTransactionType(0)
eConnect.POPTransactionType(0) = oPOPTransactionType
'Next
'Create file and XML writer objects to serialize the eConnect XML document.
Dim fs As New FileStream(filename, FileMode.Create)
Dim writer As New XmlTextWriter(fs, New UTF8Encoding)

'Use the XmlTextWriter to serializer the eConnect XML document object to the file
serializer.Serialize(writer, eConnect)
writer.Close()
Catch ex As System.ApplicationException
Console.Write("Error occured while creating the customer XML document and file")
Console.Write(ex.ToString)
End Try
End Sub
End Module

__________________________________________________________________________

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    soma Profile Picture
    24,410 on at

    Did you receive any error?

    Have you tried to debugged your code?

    If you go to the eConnect Sample folder under the eConnect installation path(By default : C:\Program Files (x86)\Microsoft Dynamics\eConnect 12.0\eConnect Samples), you can see the sample coding for Sales Order integration. Just compare with this your code. The schema's only vary for SO and PO other than the logic is same.

    Hope this helps!!!

  • Suggested answer
    soma Profile Picture
    24,410 on at

    Please replace the line

    e.CreateEntity(sConnectionString, sCustomerDocument)

    with

    e.CreateTransactionEntity(sConnectionString, sCustomerDocument)

    and try again.

    Hope this helps!!!

  • Community Member Profile Picture
    on at

    Hi,

    Please make sure the error occurs for single line item for PO or inserting multiple line item for a PO?

    if you able to insert a single line item for a PO then the problem is inserting a bulk line item for a PO.

    Please stepping your code to trace the error occurrence.

  • Verified answer
    fyurmama Profile Picture
    75 on at

    i was able to get it to work. While debugging i noticed the:

    .ITEMNMBR = "3-A2440A"

    .VNDITNUM = "131G" ' changed this to "3-A2440A"

    did not match. oops! also, the date format was incorrect:

    .DOCDATE = "04152017"

    i just commented it out and presto. thanks again for the help! i'm sure i'l be back later with another post as i work on receipt and invoicing for PO's.

    thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
mtabor Profile Picture

mtabor 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans