Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Organization Service Methods

[Applies to: Microsoft Dynamics CRM 2011]

ImportantImportant
Some links to methods in this SDK are not 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. If the query includes an aggregate function, xxx.

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

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.