eConnect - Update a Customer

I never really knew that you could retrieve a customer from Dynamics, update something on the customer, and then update the customer in Dynamics. But you can...

There article is a complete set of sample code on how to retrieve a customer and then update a customer in .NET.

If this is new to you, please go through the example on how to retrieve a customer here:

http://dyndeveloper.com/articleview.aspx?ArticleID=172

Before doing this. That entire piece of code is used in this code.

 

 

 

Imports System.IO
Imports System.Xml.Serialization
Imports Microsoft.Dynamics.GP.eConnect.Serialization
 
Public Class CustomerDeserialize
    Sub CustomerDeserialize()
        'get an XML document that represents the customer
        'this uses our CustomerRetrieve class documented here
        Dim oCustomerRetrieve As New CustomerRetrieve
        Dim strCustomer As String = oCustomerRetrieve.retrieveCustomer("aaronfit0001")
 
        '**Retrieve the customer XML**
        'Load the customer document string into a StringReader
        Dim requestReader As New StringReader(strCustomer)
 
        'Use the StringReader to populate an XML text reader
        Dim xmlTextReader As New Xml.XmlTextReader(requestReader)
 
        'Use the XML text reader to find the customer XML in the eConnect Requester response document
        'The eConnect_Out_Setup table shows that the customer XML data will
        ' be enclosed in <Customer> tags
        xmlTextReader.ReadToFollowing("Customer")
 
        Dim customerXml = xmlTextReader.ReadInnerXml()
 
        'Create a string that places the customer XML into an taUpdateCreateCustomerRcd XML node
        Dim customerObjectXml = String.Concat("<?xml version=""1.0""?><taUpdateCreateCustomerRcd>", customerXml, "</taUpdateCreateCustomerRcd>")
        'Use a StringReader to read the XML for the taUpdateCreateCustomerRcd XML node
        Dim customerReader As New StringReader(customerObjectXml)
 
        '**Deserialize the taUpdateCreateCustomerRcd XML node from the StringReader**
        Dim deSerializer As New XmlSerializer(GetType(taUpdateCreateCustomerRcd))
        'Cast the deserialized object to a taUpdateCreateCustomerRcd
        ' serialization object
        Dim otaUpdateCreateCustomerRcd = CType(deSerializer.Deserialize(customerReader), taUpdateCreateCustomerRcd)
 
        'update some fields to prove that it worked
        otaUpdateCreateCustomerRcd.ADDRESS2 = "DD was here"
 
        'this might be a bug in the system. The Finance Charge Percent field is stored as '150',
        'but eConnect requires '1.5'.
        otaUpdateCreateCustomerRcd.FNCHPCNT = otaUpdateCreateCustomerRcd.FNCHPCNT / 100
        otaUpdateCreateCustomerRcd.FNCHPCNTSpecified = 1
 
        'initialize our eConnect wrapper class, documented here:
        Dim oeConnectFunctions As New eConnect11Lib.GP11.eConnectFunctions("localhost", "two")
 
        'standard econnect update
        Dim oeConnectType As New Microsoft.Dynamics.GP.eConnect.Serialization.eConnectType
        Dim oRMCustomerMasterType As New Microsoft.Dynamics.GP.eConnect.Serialization.RMCustomerMasterType
 
        oRMCustomerMasterType.taUpdateCreateCustomerRcd = otaUpdateCreateCustomerRcd
        ReDim Preserve oeConnectType.RMCustomerMasterType(0)
        oeConnectType.RMCustomerMasterType(0) = oRMCustomerMasterType
 
        oeConnectFunctions.CreateEntity(oeConnectType)
    End Sub
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