简体   繁体   English

如何使用工作流在MS Dynamics CRM中共享记录

[英]How to share a record in MS Dynamics CRM using workflow

I would like to do the following: 我想做以下事情:

when a Sales person assigns a custom entity (let's call it 'Primary Expertise') to an Opportunity in MS CRM 4.0, the system would share the Opportunity with the user that is defined as the Owner of the associated 'Primary Expertise' record. 当销售人员将自定义实体(我们将其称为“主要专业知识”)分配给MS CRM 4.0中的商机时,系统将与定义为关联“主要专业知识”记录的所有者的用户共享商机。

I would like to do it automatically via workflow but cannot find the workflow step that would accomplish that. 我想通过工作流程自动完成,但无法找到可以实现这一目标的工作流程步骤。 Yes, and I read on some forums that it's actually not possible yet, only via a .NET assembly. 是的,我在一些论坛上读到它实际上还不可能,只能通过.NET程序集。

Experience, anyone? 经验,有人吗?

It is possible only by invoking custom workflow activity. 只能通过调用自定义工作流活动来实现。 Inside the custom workflow activity, you can invoke GrantAccessRequest and GrantAccessResponse by configuring the PrincipalAccess object. 在自定义工作流活动中,您可以通过配置PrincipalAccess对象来调用GrantAccessRequest和GrantAccessResponse

Please refer to this " Sharing Object " section for details. 有关详细信息,请参阅此“ 共享对象 ”部分。

If you'll decide to go with custom plugin, your code might look like this: 如果您决定使用自定义插件,您的代码可能如下所示:

var rights = AccessRights.ReadAccess | AccessRights.WriteAccess;

var principalAccess = new PrincipalAccess
{
    // Gives the principal read write access
    AccessMask = rights,

    // Set the PrincipalAccess Object's Properties
    Principal = sharingTarget.Key
};

// Create the Request Object
var grantAcessRequest = new GrantAccessRequest();
// Set the Request Object's properties
grantAcessRequest.PrincipalAccess = principalAccess;
// Set the Target. In my case it is account record
var entityReference = new EntityReference(localContext.PluginExecutionContext.PrimaryEntityName,
                                          localContext.PluginExecutionContext.PrimaryEntityId);
//throw new InvalidPluginExecutionException("EntityReference");
grantAcessRequest.Target = entityReference;

// Execute the Request
localContext.OrganizationService.Execute(grantAcessRequest);

Correct, it is only possible via .NET assembly. 正确,它只能通过.NET程序集。 However you could (If you using CRM 4) have the workflow change the owner to the owner of the activity and use the share with previous owner option to enable the old owner access to your custom entity? 但是,您可以(如果使用CRM 4)将工作流更改为活动所有者并使用以前所有者共享选项来启用旧所有者对自定义实体的访问权限?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM