Thursday, January 6, 2011

Programmatically Create MS CRM Account

Using CRM SDK4.0 you can customize CRM programmatically.
Download CRMSDK 4.0 from here
Then add web service reference in your project
Also you have to pass below Items in CRM Code.
- Organization Name

- Username, Password & Domain (CRM Credential)
See the below function code for CRM Account Creation.

public static void createAccount(string NewAccountName)
CrmSdk.CrmService myCrm = new CrmSdk.CrmService();
myCrm.Url = "http://CrmApplicationUrl/MSCRMServices/2007/CrmService.asmx";

CrmSdk.CrmAuthenticationToken myCrmToken = new CrmSdk.CrmAuthenticationToken();
myCrmToken.AuthenticationType = 0;
myCrmToken.OrganizationName = GetCrmOrganization();//"OrganizationName";

myCrm.CrmAuthenticationTokenValue = myCrmToken;

System.Net.NetworkCredential nc = new System.Net.NetworkCredential();
nc.UserName = "Username";//Pass Username of CRM
nc.Password = "Password";//Pass Password of above CRMAccount
nc.Domain = "Domain";//Pass Domain name

myCrm.Credentials = nc;
CrmSdk.account newAccount = new CrmSdk.account(); = NewAccountName;
Guid newAccountId = myCrm.Create(newAccount);

Happy coding !!!

No comments:

Post a Comment