locked
how to create a record in contact entity for a particular account record in dot net. RRS feed

  • Question

  • how to create a record in contact entity for a particular account record in dot net.
    Please provide me the complete code.
    Tuesday, December 29, 2009 5:42 AM

Answers

  • Hi
    after adding the web-reference  to crmservice.asmx. u can use this code.

    CrmAuthenticationToken token = new CrmAuthenticationToken();
    // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
    token.AuthenticationType = 0;
    token.OrganizationName = "AdventureWorksCycle";
     
    CrmService service = new CrmService();
    service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
    service.CrmAuthenticationTokenValue = token;
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;


    // Create the contact object.
    contact contactobj = new contact();

    // Set the properties of the contactobj object.
    contactobj.name = "Fourth Coffee";
    contactobj.address1_line1 = "23 Market St.";
    contactobj.address1_city = "Sammamish";
    contactobj.address1_stateorprovince = "MT";
    contactobj.address1_postalcode = "99999";
    contactobj.donotbulkemail = new CrmBoolean();
    contactobj.donotbulkemail.Value = true;

    // set  the contact parent customer id
    contactobj.parentcustomerid  = new Customer();
    contactobj.parentcustomerid.type = EntityName.account.ToString();
    contactobj.parentcustomerid.value = new Guid("account guid here");

    Guid newID = service.Create(contactobj);

    Tuesday, December 29, 2009 5:59 AM