Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Organization service methods

Applies To: CRM 2015 on-prem, CRM Online

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.

Use the IOrganizationService.Create method to create an instance (record) of any entity that supports the Create message, including custom entities.

Use the IOrganizationService.Retrieve method to retrieve an instance (record) of an entity.

Use the IOrganizationService.RetrieveMultiple method to retrieve a collection records. The query can be specified using a query expression or Fetch XML query.

Use the IOrganizationService.Update method to update an existing record.

Use the IOrganizationService.Delete method to delete an existing record.

Use the IOrganizationService.Associate method to create a link between two records that participate in a relationship.

Use the IOrganizationService.Disassociate method to delete the link between two records.

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.

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
Console.WriteLine("An account and {0} letters were updated.", _letterIds.Length);

See Also

Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online
Send comments about this topic to Microsoft.
© 2015 Microsoft. All rights reserved.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft