Thursday, January 6, 2011

Programmatically Create MS CRM Account

Using CRM SDK4.0 you can customize CRM programmatically.
Download CRMSDK 4.0 from here
http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=82e632a7-faf9-41e0-8ec1-a2662aae9dfb&displaylang=en
Then add web service reference in your project
Example:
http://CrmApplicationUrl/MSCRMServices/2007/CrmService.asmx
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();

newAccount.name = NewAccountName;
Guid newAccountId = myCrm.Create(newAccount);
}



Happy coding !!!

No comments:

Post a Comment