Organization service methods
Applies To: Dynamics CRM 2013
Important
Some links to methods in this SDK aren’t working. You can get to the documentation for the web service methods from this page: IOrganizationService.
The IOrganizationService web service provides a set of methods used to perform the most common operations on system and custom entities and on the metadata for your organization. These operations can also be performed by using the IOrganizationService.Execute method and the corresponding message.
Create
Use the IOrganizationService.Create method to create an instance (record) of any entity that supports the Create message, including custom entities.
Retrieve
Use the IOrganizationService.Retrieve method to retrieve an instance (record) of an entity.
RetrieveMultiple
Use the IOrganizationService.RetrieveMultiple method to retrieve a collection records. The query can be specified using a query expression or Fetch XML query.
Update
Use the IOrganizationService.Update method to update an existing record.
Delete
Use the IOrganizationService.Delete method to delete an existing record.
Associate
Use the IOrganizationService.Associate method to create a link between two records that participate in a relationship.
Disassociate
Use the IOrganizationService.Disassociate method to delete the link between two records.
Execute
Use the IOrganizationService.Execute method to execute a message. This includes common processing like create and delete of data records and metadata, or it can be specialized processing such as import or detect duplicates.
Example
The following code shows how to use the Create, Retrieve, and Update methods using the strong types.
//Define the account for which we will add letters
Account accountToCreate = new Account
{
Name = "Example Account"
};
//Define the IDs of the related letters we will create
_letterIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
//This acts as a container for each letter we create. Note that we haven't
//define the relationship between the letter and account yet.
EntityCollection relatedLettersToCreate = new EntityCollection
{
EntityName = Letter.EntityLogicalName,
Entities =
{
new Letter{Subject = "Letter 1", ActivityId = _letterIds[0]},
new Letter{Subject = "Letter 2", ActivityId = _letterIds[1]},
new Letter{Subject = "Letter 3", ActivityId = _letterIds[2]}
}
};
//Creates the reference between which relationship between Letter and
//Account we would like to use.
Relationship letterRelationship = new Relationship("Account_Letters");
//Adds the letters to the account under the specified relationship
accountToCreate.RelatedEntities.Add(letterRelationship, relatedLettersToCreate);
//Passes the Account (which contains the letters)
_accountId = _service.Create(accountToCreate);
Console.WriteLine("An account and {0} letters were created.", _letterIds.Length);
//Now we run through many of the same steps as the above "Create" example
Account accountToUpdate = new Account
{
Name = "Example Account - Updated",
AccountId = _accountId
};
EntityCollection relatedLettersToUpdate = new EntityCollection
{
EntityName = Letter.EntityLogicalName,
Entities =
{
new Letter{Subject = "Letter 1 - Updated", ActivityId = _letterIds[0]},
new Letter{Subject = "Letter 2 - Updated", ActivityId = _letterIds[1]},
new Letter{Subject = "Letter 3 - Updated", ActivityId = _letterIds[2]}
}
};
accountToUpdate.RelatedEntities.Add(letterRelationship, relatedLettersToUpdate);
//This will update the account as well as all of the related letters
_service.Update(accountToUpdate);
Console.WriteLine("An account and {0} letters were updated.", _letterIds.Length);
See Also
IOrganizationService
Use the IOrganizationService web service to read and write data or metadata
Use messages (request and response classes) with the Execute method
Use ExecuteMultiple to improve performance for bulk data load
xRM messages in the Organization service
CRM messages in the organization service
Authenticate users with Microsoft Dynamics CRM 2013 web services
Sample: Create, retrieve, update, and delete records (early bound)
Sample: Create, retrieve, update, and delete (late bound)