CRM 2011自定义工作流从创建的记录触发器访问数据

时间:2014-01-31 18:58:35

标签: c# dynamics-crm-2011

我正在创建一个自定义工作流程 - 在创建记录时触发(自定义活动)。

我需要能够在我的自定义工作流程中访问上面的自定义活动中的数据,但我很难找到有关如何从新创建的记录中获取信息的参考。

有什么建议吗? 提前致谢。

编辑:

public sealed class FeeInvoiceGenerator : CodeActivity
{

    [Input("MyFee")]
    [ReferenceTarget("fee")]
    [RequiredArgument]
    public InArgument<EntityReference> SomeFee { get; set; }

    protected override void Execute(CodeActivityContext executionContext)
    {
        ITracingService tracingService = executionContext.GetExtension<ITracingService>(); 
        try
        {
            tracingService.Trace("Creating Invoice for Fee");
            WorkFlowHelper workFlowHelper = new WorkFlowHelper();
            workFlowHelper.debugMessagesOn = true;

            //creates connection info
            InvoiceFeeHelper invoiceFeeHelper = new InvoiceFeeHelper();
            invoiceFeeHelper.ConnectionInfo(workFlowHelper);
            invoiceFeeHelper.CreatingConnection(workFlowHelper, executionContext);

            //initialize other classes
            FeeMaster feeMaster = new FeeMaster();
            InvoiceMaster invoiceMaster = new InvoiceMaster();
            InvoiceFeeMaster invoiceFeeMaster = new InvoiceFeeMaster();

            EntityReference getFee = this.SomeFee.Get(executionContext);

            String feeId = getFee.Id.ToString();


            invoiceFeeMaster.CreateInvoiceFromFee(workFlowHelper, invoiceFeeHelper, invoiceMaster, feeMaster, feeId, executionContext);

        }
        catch (Exception ex)
        {
            throw new NotImplementedException("error occured" + ex.Message);
        }

    }

}

但是,我遇到了一个问题,我无法访问工作流程本身的[设置属性]来分配输入。 (至少这是我在网上看到的其他例子,对我来说是空白的)enter image description here

我也尝试过使用:

IWorkflowContext workFlowContext = workFlowHelper.context.GetExtension<IWorkflowContext>();

            Guid _feeRecordID = workFlowContext.PrimaryEntityId;

为了获取记录ID无济于事。我的自定义工作流程的其他部分工作,如果我从'费'(我需要抓住的记录)传入一个guid,一切都很好。

我做错了吗?

第二次编辑: 我需要在CRM服务器上重新启动IIS才能识别出要使用的输入。

2 个答案:

答案 0 :(得分:2)

你可以通过几种方式做到这一点:

  1. 使用输入参数传递所需的所有数据。
  2. 使用输入参数传递记录的ID,然后使用IOrganizationService检索其余数据。
  3. 有关示例和详细信息,请参阅Custom Workflow Activities (Workflow Assemblies) for Microsoft Dynamics CRM

答案 1 :(得分:0)

我不确定你的WorkflowHelper做了什么,但你不应该真的使用它。

    // Create the context
    var context = executionContext.GetExtension<IWorkflowContext>();
    //primary entityid
    var _feeRecordId = context.PrimaryEntityId
相关问题