分享方式:


範例:將資訊安全角色與團隊建立關聯

 

發佈日期: 2017年1月

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

這個範例程式碼適用於 Microsoft Dynamics 365 (線上和內部部署)。下載 Microsoft Dynamics CRM SDK 套件。 可以在下列位置的下載套件中找到:

SampleCode\CS\GeneralProgramming\EarlyBound\AssignSecurityRoleToTeam.cs

需求

如需執行此 SDK 所提供範例程式碼的需求資訊,請參閱使用範例和 Helper 程式碼

示範

此範例顯示如何使用 AssignRequest 訊息將資訊安全角色指派給團隊。 請注意,此範例並未將團隊或使用者只能接受一個來自其業務單位的角色指派之情形納入考量。 要指派的角色是 RetrieveMultiple 方法所傳回集合中的第一個。 如果該記錄的所屬業務單位與提出要求的團隊不同,則指派將會失敗。

範例



// Retrieve a role from CRM.
QueryExpression query = new QueryExpression
{
    EntityName = Role.EntityLogicalName,
    ColumnSet = new ColumnSet("roleid"),
    Criteria = new FilterExpression
    {
        Conditions =
    {
        // You would replace the condition below with an actual role
        // name, or skip this query if you had a role id.
        new ConditionExpression
        {
            AttributeName = "name",
            Operator = ConditionOperator.Equal,
            Values = {_roleName}
        }
    }
    }
};

Role role = _service.RetrieveMultiple(query).Entities.
    Cast<Role>().First();


// Add the role to the team.
_service.Associate(
       Team.EntityLogicalName,
       _teamId,
       new Relationship("teamroles_association"),
       new EntityReferenceCollection() { new EntityReference(Role.EntityLogicalName, _roleId) });

Console.WriteLine("Assigned role to team");

另請參閱

AssignRequest
指派​​
權限與角色實體
範例:將資訊安全角色與使用者建立關聯
使用者與團隊實體

Microsoft Dynamics 365

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