Using CreateEntity for new records
The eConnectMethods class enables your .NET application to add new data records in Microsoft Dynamics GP. To create a record, use the following methods:
Method |
Description |
---|---|
CreateEntity |
Creates a record using information from an eConnect XML document. Use CreateEntity to add data entities like customers or vendors. You specify the type of record to create with a parameter that represents an eConnect XML document. If the operation succeeds, the method returns True as a boolean value. |
CreateTransactionEntity |
Create a transaction using information from an eConnect XML document. Use CreateTransactionEntity for transaction documents like sales orders or inventory transactions. You specify the type of transaction to create with a parameter that represents an eConnect XML document. If the operation succeeds, the method returns an XML string that represents the eConnect XML document that was created. |
The eConnectMethods class also includes methods to update or delete existing records in Microsoft Dynamics GP. To use these methods, you must supply the eConnect XML document for the specified operation and document type.
To create, update, and delete or void a record in Microsoft Dynamics GP, you must create an XML string for your eConnect XML document. The following are the most common techniques for creating this string.
Construct a string that contains the eConnect XML schema and node tags that are required for your operation. In addition, include the XML tags and values for the XML elements that you want to populate with data.
Load text from a file or other data store that contains an existing eConnect XML document into a .NET XmlDocument object. Use the OuterXML property of the XmlDocument class to convert the XML document to a string.
Warning: To work with eConnect, the text that is loaded into the XmlDocument object must be a valid eConnect XML document.
Use classes from the eConnect Serialization namespace to construct an object that represents an eConnect XML document. Use a .NET XmlSerializer and a XmlDocument object to convert your document object to a string.
For more information about eConnect XML documents, see .eConnect XML document structure.
The following steps show how to use the CreateEntity method to create a record using XML from a textbox control.
Instantiate an eConnectMethods object
To begin, instantiate an eConnectMethods object. The following Visual Basic example shows how to instantiate an eConnectMethods object:
'Instantiate an eConnectMethods object Dim eConnectObject As New eConnectMethods
Load the eConnect XML document
The following Visual Basic example shows how to use the XML text from a textbox control as the source of the eConnect XML document. Notice how text from the specified control is loaded into a .NET XmlDocument object.
'Load the text from the textbox control into an XmlDocument object Dim xmlDoc As XmlDocument xmlDoc.LoadXml(XmlDoc_TextBox.Text)
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 Visual Basic example shows how to creates a connection string:
'Set the connection string 'This connection string uses integrated security to connect to the 'TWO database on the local computer Dim ConnectionString As String ConnectionString = "Data Source=localhost;Integrated Security=SSPI;" _ & "Persist Security Info=False;Initial Catalog=TWO;"
Submit the eConnect document
Use the CreateEntity method to submit the document to the eConnect business objects. To call the CreateEntity method, supply parameters that specify the connection string, and the eConnect XML document string.
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 Visual Basic example uses the CreateEntity method to submit an eConnect XML document. Notice the following:
- The ConnectionString parameter specifies the Dynamics GP data server and the company database.
- The XML string parameter is created using the OuterXml property of the XmlDocument object.
'If eConnectResult is TRUE, the XML document was successfully submitted Dim eConnectResult As Boolean eConnectResult = eConnectObject.CreateEntity(ConnectionString, _ xmlDoc.OuterXml)