After create a CrmService with your organization, server, domain, username and password information, I continue to create this tutorial to show you how to create an Account by using Microsoft Dynamics CRM Web Services.
If should read this tutorial on my site to know how to create a CrmService if you haven’t read it yet.
I will re use the IFDConnectionDemo function in the previous tutorial to create CrmService Web service connection.
The CrmService Web service provides a set of methods, this tutorial will give an example for Create method.
The C# source code below will:
- Create a CRM Service instance
- Create an Account entity and assign data to some attributes
- Call the Create method to create the Account
- Display the new Account GUID (Account ID)
Here you go – file create_account.aspx in the source code attachment:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.Crm.Sdk; using Microsoft.Crm.Sdk.Query; using Microsoft.Crm.SdkTypeProxy; using CRM; public partial class create_account : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string organization = "your-organization"; string server = "your-server:your-port-number-if-any"; string domain = "your-domain"; string username = "your-username"; string password = "your-password"; //Create CRM Service instance CrmService service = crm_demo.IFDConnectionDemo(organization, server, domain, username, password); //Create Account entity and assign data to some attributes account newAccount = new account(); newAccount.name = "Hoan Huynh"; newAccount.accountnumber = "123456"; newAccount.address1_postalcode = "98052"; newAccount.address1_city = "HCM"; newAccount.emailaddress1 = "[email protected]"; newAccount.address1_telephone1 = "089666541"; newAccount.description = "Some note here ..."; newAccount.telephone1 = "0909345541"; // Call the Create method to create the account. Guid accountId = service.Create(newAccount); //Display the new Account GUID (Account ID) Response.Write("accountId: " + accountId.ToString() + "<br>"); //0b00108f-8757-e011-a444-e61f13c072b3 } } |
I captured some screen for you can preview the result:
1. Display Account ID
2. Result for Account Page:
3. Result for Account General Information Page:
4. Result for Account Detail Information Page:
Download the source code above