我正在编写一个使用业务流程流程的活动插件。由活动实体中的业务流程流创建的字段ProcessId和StageId。我需要为插件中的记录检索这些值。
它们不会出现在插件注册工具的Step图像中。如果我可以在其他领域填充它们,它们甚至不会出现在CRM工作流中。
对于我如何做到这一点,有什么好的选择吗?
发布于 2015-07-29 08:04:01
您应该能够通过将正确的输入参数传递给此业务流程流中的workflow activity来检索该参数。
1)如果有这些字符串输入:
[RequiredArgument]
[Input("Process Name")]
public InArgument Process { get; set; }
[RequiredArgument]
[Input("Process Stage Name")]
public InArgument ProcessStage { get; set; }2)执行代码Get Process
using (var _context= new OrganizationServiceContext(service))
{
// Get the processid using the name provided
var process = (from p in _context.CreateQuery()
where
p.Name == Process.Get(executionContext)
&&
p.StateCode == WorkflowState.Activated
select new Workflow
{WorkflowId = p.WorkflowId}
).FirstOrDefault();
if (process==null)
throw new InvalidPluginExecutionException(string.Format("Process '{0}' not found",Process.Get(executionContext)));使用提供的名称获取stage id
var stage = (from s in _context.CreateQuery()
where
s.StageName == ProcessStage.Get(executionContext)
&&
s.ProcessId.Id == process.WorkflowId
select new ProcessStage
{ProcessStageId = s.ProcessStageId}
).FirstOrDefault();
if (stage == null)
throw new InvalidPluginExecutionException(string.Format("Stage '{0}' not found", Process.Get(executionContext)));您现在可以使用检索到的值来Change Update这个舞台了..。
Entity uStage = new Entity(context.PrimaryEntityName);
uStage.Id = context.PrimaryEntityId; //
uStage["stageid"] = stage.ProcessStageId; //retrieved stage
uStage["processid"] = process.WorkflowId; //process id发布于 2015-07-29 08:47:44
为什么不从您的IServiceProvider中获取一个服务并检索这些字段呢?
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = CommonPluginLibrary.GetContextFromIServiceProvider(serviceProvider);
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
Entity campaign = service.Retrieve(context.PrimaryEntityId, context.PrimaryEntityName, new ColumnSet("processid", "stageid"));
// ...
// Do your stuff with campaign["processid"], campaign["stageid"]
// ...
}另一种方法是为stageid和processid创建两个影子字段(例如new_stageid、new_processid),并使用在进程/阶段更新时触发的同步工作流填充这些字段。
然后,您可以在这些阴影字段上注册插件,因为它们是实体的自定义属性。
发布于 2015-07-29 07:57:30
要访问进程和阶段ids,可以使用processid和stageid记录字段。我很肯定,你可以从图片或通过直接阅读的记录。此外,您还可以重新检查以下文章:https://deepakexploring.wordpress.com/tag/updating-process-id-in-crm-2013/
https://stackoverflow.com/questions/31694066
复制相似问题