共用方式為


組織服務方法

 

發行︰ 2017年1月

適用於: Dynamics 365 (online)、Dynamics 365 (on-premises)、Dynamics CRM 2016、Dynamics CRM Online

IOrganizationService web 服務提供一組方法,用來執行大多數系統、自訂實體,以及您組織中繼資料的一般作業。 這些作業可以使用 IOrganizationService.Execute 方法和對應的訊息執行。

建立

使用 IOrganizationService.Create 方法來建立任何支援建立訊息的實體執行個體,包括自訂實體。

擷取

使用 IOrganizationService.Retrieve 方法來擷取實體的執行個體 (紀錄)。

RetrieveMultiple

使用 IOrganizationService.RetrieveMultiple 方法來擷取關係紀錄。 查詢可以指定使用查詢運算式或是 Fetch XML 查詢。

更新

使用 IOrganizationService.Update 方法來更新現存紀錄。

刪除​​

使用 IOrganizationService.Delete 方法來刪除現存紀錄。

Associate

使用 IOrganizationService.Associate 方法來建立兩筆參與關聯資料的連結。

Disassociate

使用 IOrganizationService.Disassociate 方法來刪除兩筆記錄間的連結。

執行

使用 IOrganizationService.Execute 方法來執行訊息。 這包括一般的處理,像是建立或刪除資料紀錄和中繼資料,或是可以特殊處理的作業,例如匯入或偵測重複資料。

範例

下列程式碼示範如何使用強類型的 CreateRetrieve、和 Update 方法。


//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);

另請參閱

IOrganizationService
使用組織服務讀取和寫入資料或中繼資料
使用訊息 (請求和回覆類別) 搭配 Execute 方法
使用 ExecuteMultiple 提升大量資料載入的效能
組織服務中的 xRM 訊息
組織服務中的 Dynamics 365 訊息
在 Microsoft Dynamics 365 中驗證使用者
範例:建立、擷取、更新和刪除紀錄 (早期繫結)
範例:建立、擷取、更新和刪除 (晚期繫結)

Microsoft Dynamics 365

© 2017 Microsoft. 著作權所有,並保留一切權利。 著作權