CrmService.Create Method

Creates an instance of an entity.

Syntax

public Guid Create(
  BusinessEntity  entity
);






Parameters

entity

Specifies an instance of a class derived from BusinessEntity of the type of entity to create.

Return Value

Returns a Guid type that contains the ID of the newly created entity.

Remarks

Use this method to create an instance of any Microsoft Dynamics CRM entity that supports the Create message.

For better performance, use this method instead of using the Execute method with the Create message.

To perform this action, the caller must have access rights on the entity instance specified in the request class. For a list of required privileges, see Create Privileges.

The owner of the newly created instance should also have the Read privilege for the entity type.

Example

The following example demonstrates the use of the Create method.



   1:  //# [CrmService.Create Method]

   2:  // Set up the CRM Service.

   3:  CrmAuthenticationToken token = new CrmAuthenticationToken();

   4:  // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.

   5:  token.AuthenticationType = 0; 

   6:  token.OrganizationName = "AdventureWorksCycle";

   7:   

   8:  CrmService service = new CrmService();

   9:  service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";

  10:  service.CrmAuthenticationTokenValue = token;

  11:  service.Credentials = System.Net.CredentialCache.DefaultCredentials;

  12:   

  13:  // Create the contact object.

  14:  contact contact = new contact();

  15:   

  16:  // Create the properties for the contact object.

  17:  contact.firstname = "Jesper";

  18:  contact.lastname = "Aaberg";

  19:  contact.address1_line1 = "23 Market St.";

  20:  contact.address1_city = "Sammamish";

  21:  contact.address1_stateorprovince = "MT";

  22:  contact.address1_postalcode = "99999";

  23:  contact.donotbulkemail = new CrmBoolean();

  24:  contact.donotbulkemail.Value = true;

  25:   

  26:  // Create the contact in Microsoft Dynamics CRM.

  27:  Guid contactGuid = service.Create(contact);