简体   繁体   English

如何确定CRM 2011中的工作流模式?

[英]How to determine the Workflow Mode in the CRM 2011?

I want to determine how the workflow is initiated (background/asynchronous) or (real-time/on-demand) in the Microsoft CRM 2011? 我想确定在Microsoft CRM 2011中如何启动(后台/异步)或(实时/按需)工作流? In both of the OOB Workflow Conditions and within a Custom Workflow Activity? 在OOB工作流程条件中还是在自定义工作流程活动中?

Based on the following link, I can see Microsoft introduced a new property ( IWorkflowContext.WorkflowMode ) in CRM 2013 SDK to expose that. 基于以下链接,我可以看到Microsoft在CRM 2013 SDK中引入了新属性( IWorkflowContext.WorkflowMode )来公开该属性。 I want the same information in CRM 2011. 我想要CRM 2011中的相同信息。

http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.workflow.iworkflowcontext.workflowmode(v=crm.6).aspx http://msdn.microsoft.com/zh-cn/library/microsoft.xrm.sdk.workflow.iworkflowcontext.workflowmode(v=crm.6).aspx

I do not think that it is possible to differentiate between on-demand and triggered workflows in the workflow designer. 我认为无法在工作流设计器中区分按需工作流和触发工作流。

In a custom workflow activity there will only be the Target input parameter if the workflow was started by a trigger: 在自定义工作流程活动中,如果工作流程是由触发器启动的,则只有Target输入参数:

var context = activityContext.GetExtension<IWorkflowContext>();
if (context.InputParameters.Contains("Target"))
{
    // Started by a trigger
}
else
{
    // Started on demand
}

In addition to that you can determine what kind of trigger started the workflow by the type of Target. 除此之外,您还可以通过Target的类型确定哪种触发器启动了工作流程。 This info is also available in context.MessageName which contains the string "Update" in the case of an update message. 此信息在context.MessageName中也可用,如果有更新消息,则包含字符串“ Update”。

if (context.MessageName == "Update")
    // this is an update message
var context = activityContext.GetExtension<IWorkflowContext>();
if (context.InputParameters.Contains("Target"))
{
    if (context.InputParameters["Target"].GetType() == typeof(Entity))
    {
        // create and update are Entity
    }
    else if (context.InputParameters["Target"].GetType() == typeof(EntityReference))
    {
        // delete and some other operations are EntityReference
    }       
}
else
{
    // Started on demand
}

Which specific fields were updated can be determined by which attributes Target contains. 可以通过Target包含哪些属性来确定更新了哪些特定字段。
This could be used to determine which field triggered the workflow. 这可用于确定哪个字段触发了工作流。
If a create message triggered the workflow then Target will contain all fields (that the user entered). 如果创建消息触发了工作流程,则Target将包含所有字段(用户输入的字段)。 To be certain that the workflow was triggered by an update of a field you could use context.MessageName in conjunction with checking which attributes Target contains. 要确定工作流是由字段更新触发的,可以将context.MessageName与检查Target包含的属性结合使用。

The functionality you seek does not exist in CRM 2011. All workflows in CRM 2011 run asynchronously therefore there is no need for IWorkflowContext.WorkflowMode . 您寻求的功能在CRM 2011中不存在IWorkflowContext.WorkflowMode所有工作流都是异步运行的,因此不需要IWorkflowContext.WorkflowMode

You cannot make CRM 2011 run an OOTB workflow synchronously. 您不能使CRM 2011同步运行OOTB工作流。 If you want to execute code during the transaction, the way CRM 2013 can do with synchronous workflows, you must code the logic in a Plugin. 如果要在交易过程中执行代码(CRM 2013可以使用同步工作流执行的方式),则必须在插件中编写逻辑代码。

I think you can achieve your goals by adding a “hidden” field on your entity and creating a couple “handler” workflows that populate this field then fire your “actual” workflow. 我认为您可以通过在实体上添加“隐藏”字段并创建几个填充该字段的“处理程序”工作流,然后触发“实际”工作流来实现您的目标。

Step 1. Create a field on your entity to hold a value indicating the initiator 步骤1.在您的实体上创建一个字段以保存一个值,该值指示发起者

Step 2. Create the “actual” workflow as a child process 步骤2.将“实际”工作流程创建为子流程

Step 3. Create an on-demand (only) workflow that: 步骤3.创建一个按需(仅)工作流:
a. 一种。 Sets a value on the entity in the “initiator” field indicating the workflow was run manually. 在“启动器”字段中的实体上设置一个值,指示工作流是手动运行的。
b. b。 Calls the child workflow 调用子工作流程

Step 4. Create a workflow with on-demand not selected that: 步骤4.创建一个未选择按需选择的工作流:
a. 一种。 Sets a value on the entity in the “initiator “ field indicating the workflow was automated. 在“启动器”字段中的实体上设置一个值,以指示工作流程已自动化。
b. b。 Calls the child workflow 调用子工作流程

Step 5. Show the result 步骤5.显示结果
a. 一种。 Create an “admin” form that displays this value and/or, 创建一个显示该值的“管理员”表单和/或,
b. b。 Make the field hidden on the user form and show via js as appropriate and/or, 将字段隐藏在用户表单上,并根据需要通过js显示和/或,
c. C。 Create a view that includes displays this field and/or, 创建一个包含显示此字段的视图和/或,
d. d。 Create a report that includes this field and/or, 创建包含此字段的报告和/或,
e. e。 Check the value of this field in your code 检查代码中此字段的值

Unless there is specific value, this field would not be included on user forms or views. 除非有特定值,否则该字段将不会包含在用户表单或视图中。

By using a custom field and populating it via “handler” workflows you will be able to achieve your OOB goal. 通过使用自定义字段并通过“处理程序”工作流填充它,您将能够实现OOB目标。 (That is if you consider using the web GUI to create custom fields and workflows “OOB”.) (也就是说,如果您考虑使用Web GUI创建自定义字段和工作流程“ OOB”。)

By checking the value of this field programmatically you will achieve your Custom Workflow goal. 通过以编程方式检查此字段的值,您将实现您的“自定义工作流”目标。

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

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