Using the CreateEntity method to add a record
The eConnectClient class of the eConnect Integration Service includes methods that create, update, delete, and retrieve Microsoft Dynamics GP data. In addition, the class includes methods you can use to retrieve and restore Microsoft Dynamics GP document numbers.
To learn how to use the eConnectClients class, use the following steps to create a customer in Microsoft Dynamics GP. The example shows how to use the CreateEntity method of the eConnectClient class.
Add a service reference to the project
To begin, use Visual Studio to add a service reference to the eConnect Integration Service. In the Solution Explorer, right-click References, and then click Add Service Reference. In the Add Service Reference window, enter the following in Address, and then click Go.
net.pipe://localhost/Microsoft/Dynamics/GP/eConnect
Click eConnect in the list of Services and type a Namespace value that specifies a name for the service reference. For example, enter eConnectIntegrationService.
Add the service namespace to the project
Use the service reference name you entered in the previous step to add the namespace in your Visual Studio project. To add the namespace in C#, you add a using statement. To add the namespace in Visual Basic you add an Imports statement.
The following C# example adds a using statement that specifies a namespace from the service reference. In this example, ServiceTestApp is the name of the application project and eConnectIntegrationService is the name specified for the service reference.
using ServiceTestApp.eConnectIntegrationService;
Instantiate an eConnectClient object
To use the integration service, instantiate an eConnectClient object. The object includes the CreateEntity method you use to add a customer to Microsoft Dynamics GP.
The following C# example shows how to use the eConnectClient constructor to create the object:
// Instantiate an eConnectClient object eConnectClient eConnectObject = new eConnectClient();
Use an XML file to load the customer document
To create a customer you use an eConnect XML document that includes the data for the customer. One way to get the customer document is to create an XML file that contains the customer information. For information about how to create an eConnect XML document for a customer, see Create a customer.
The following C# example shows how to load an eConnect XML document from a file. Notice how the text from the specified file is loaded into a .NET XmlDocument object. Also notice how an XML string is created using the OuterXml property of the XmlDocument object.
// Use the XML document in the specified file to create // a string representation of the customer XmlDocument newCustDoc = new XmlDocument(); newCustDoc.Load("CustomerCreate.xml"); string newCustomerDocument = newCustDoc.OuterXml;
Create an eConnect connection string
The CreateEntity method requires an eConnect connection string. You use the connection string to specify the Dynamics GP data server and the company database.
For information about eConnect connection strings, see the eConnect Installation chapter of the eConnect Installation and Administration Guide.
The following C# example shows how to create a connection string:
//Create a connection string string connectionString = "Data Source=localhost;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TWO;";
Use CreateEntity to submit the customer document
Use the CreateEntity method to submit the document to the eConnect business objects. To use the CreateEntity method, you have to supply parameters that specify the connection string, and the customer.
The CreateEntity method returns a boolean value that indicates whether the XML document was successfully submitted. A return value of True indicates the operation succeeded.
The following C# example uses the CreateEntity method to submit an eConnect XML document. Notice that the first parameter is the connection string. Also notice that the second parameter is the string that represents the eConnect XML document for the customer.
// If eConnectResult is TRUE, the XML document was successfully submitted bool result = eConnectObject.CreateEntity(connectionString, newCustomerDocument);