eConnect - Retrieve a Customer

This is our first article on retrieving objects using eConnect, so this is all new ground. I expect we'll be fine tuning the code and developing wrapper classes... but this is what we have for now.

This is sample code to retrieve a customer from Dynamics using eConnect. The customer that we get back looks like this:

 

<root>
    <eConnect ACTION="0" Requester_DOCTYPE="Customer" DBNAME="TWO" TABLENAME="RM00101" DATE1="1900-01-01T00:00:00" CUSTNMBR="AARONFIT0001">
        <Customer>
            <CUSTNMBR>AARONFIT0001</CUSTNMBR>
            <ADDRESS1>One Microsoft Way</ADDRESS1>
            <ADDRESS2></ADDRESS2>
            <ADDRESS3></ADDRESS3>
            <ADRSCODE>PRIMARY</ADRSCODE>
            <CITY>Redmond</CITY>
            <CNTCPRSN>Bob Fitz</CNTCPRSN>
            <COUNTRY>USA</COUNTRY>
            <CPRCSTNM></CPRCSTNM>
            <CURNCYID>Z-US$</CURNCYID>
            <CUSTCLAS>USA-ILMO-T1</CUSTCLAS>
            <CUSTDISC>0</CUSTDISC>
            <CUSTNAME>Aaron Fitz Electrical</CUSTNAME>
            <PHONE1>42555501010000</PHONE1>
            <PHONE2>00000000000000</PHONE2>
            <PHONE3></PHONE3>
            <FAX>31255501010000</FAX>
            <PYMTRMID>Net 30</PYMTRMID>
            <SALSTERR></SALSTERR>
            <SHIPMTHD>LOCAL DELIVERY</SHIPMTHD>
            <SLPRSNID></SLPRSNID>
            <STATE>WA</STATE>
            <TAXSCHID>MYSCHED</TAXSCHID>
            <TXRGNNUM></TXRGNNUM>
            <UPSZONE></UPSZONE>
            <ZIP>98052-6399</ZIP>
            <STMTNAME>Aaron Fitz Electrical</STMTNAME>
            <SHRTNAME>Aaron Fitz Elec</SHRTNAME>
            <PRBTADCD>PRIMARY</PRBTADCD>
            <PRSTADCD>WAREHOUSE</PRSTADCD>
            <STADDRCD>PRIMARY</STADDRCD>
            <CHEKBKID>UPTOWN TRUST</CHEKBKID>
            <CRLMTTYP>1</CRLMTTYP>
            <CRLMTAMT>0.00000</CRLMTAMT>
            <CRLMTPER>0</CRLMTPER>
            <CRLMTPAM>0.00000</CRLMTPAM>
            <RATETPID></RATETPID>
            <PRCLEVEL>SPECIAL</PRCLEVEL>
            <MINPYTYP>0</MINPYTYP>
            <MINPYDLR>0.00000</MINPYDLR>
            <MINPYPCT>0</MINPYPCT>
            <FNCHATYP>1</FNCHATYP>
            <FNCHPCNT>150</FNCHPCNT>
            <FINCHDLR>0.00000</FINCHDLR>
            <MXWOFTYP>2</MXWOFTYP>
            <MXWROFAM>25.00000</MXWROFAM>
            <COMMENT1></COMMENT1>
            <COMMENT2></COMMENT2>
            <USERDEF1>925485US00</USERDEF1>
            <USERDEF2>925485US00</USERDEF2>
            <TAXEXMT1></TAXEXMT1>
            <TAXEXMT2></TAXEXMT2>
            <BALNCTYP>0</BALNCTYP>
            <STMTCYCL>5</STMTCYCL>
            <BANKNAME></BANKNAME>
            <BNKBRNCH></BNKBRNCH>
            <FRSTINDT>1900-01-01T00:00:00</FRSTINDT>
            <INACTIVE>0</INACTIVE>
            <HOLD>0</HOLD>
            <CRCARDID></CRCARDID>
            <CRCRDNUM></CRCRDNUM>
            <CCRDXPDT>1900-01-01T00:00:00</CCRDXPDT>
            <KPDSTHST>1</KPDSTHST>
            <KPCALHST>1</KPCALHST>
            <KPERHIST>1</KPERHIST>
            <KPTRXHST>1</KPTRXHST>
            <CREATDDT>1980-01-01T00:00:00</CREATDDT>
            <MODIFDT>2012-04-13T00:00:00</MODIFDT>
            <Revalue_Customer>1</Revalue_Customer>
            <Post_Results_To>0</Post_Results_To>
            <FINCHID></FINCHID>
            <GOVCRPID></GOVCRPID>
            <GOVINDID></GOVINDID>
            <DISGRPER>0</DISGRPER>
            <DUEGRPER>0</DUEGRPER>
            <DOCFMTID></DOCFMTID>
            <Send_Email_Statements>0</Send_Email_Statements>
            <GPSFOINTEGRATIONID></GPSFOINTEGRATIONID>
            <INTEGRATIONSOURCE>0</INTEGRATIONSOURCE>
            <INTEGRATIONID></INTEGRATIONID>
        </Customer>
    </eConnect>
</root>

 This is our code. It should run unmodified from the TWO database.

 

 

Imports Microsoft.Dynamics.GP.eConnect
Imports Microsoft.Dynamics.GP.eConnect.Serialization
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
 
Public Class CustomerRetrieve
    Public Function retrieveCustomer(ByVal strCustomerNumber As String) As String
        'Instantiate an eConnectMethods object
        Dim eConnectObject As New eConnectMethods
 
        '**Create an eConnect requestor document that specifies a single customer**
        'Create the requestor node
        Dim myRequest As New eConnectOut()
        With myRequest
            .DOCTYPE = "Customer"
            .OUTPUTTYPE = 1
            .INDEX1FROM = strCustomerNumber
            .INDEX1TO = strCustomerNumber
            .FORLIST = 1
        End With
 
        'Create the requestor schema document type
        'Since the eConnect document requires an array, create an
        'array of RQeConnectOutType
        Dim econnectOutType() As RQeConnectOutType = New RQeConnectOutType(0) {New RQeConnectOutType}
        econnectOutType(0).eConnectOut = myRequest
 
        'Create the eConnect document type
        Dim eConnectDoc As New eConnectType()
        eConnectDoc.RQeConnectOutType = econnectOutType
 
        '**Serialize the eConnect document**
        'Create a memory stream for the serialized eConnect document
        Dim memStream As New MemoryStream()
 
        'Create an Xml Serializer and serialize the eConnect document
        'to the memory stream
        Dim serializer As New XmlSerializer(GetType(eConnectType))
        serializer.Serialize(memStream, eConnectDoc)
 
        'Reset the position property to the start of the buffer
        memStream.Position = 0
 
        '**Load the serialized Xml into an Xml document**
        Dim xmldoc As New XmlDocument()
        xmldoc.Load(memStream)
 
        'Create an eConnect connection string
        Dim connectionString As String
        connectionString = "data source=localhost; initial catalog=TWO;integrated security=SSPI; persist security info=False;packet size=4096"
 
        'Retrieve the specified document
        Dim oeConnectMethods As New eConnectMethods
 
        Dim customerDoc = oeConnectMethods.GetEntity(connectionString, xmldoc.OuterXml)
        Return customerDoc
    End Function
End Class

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences