如何在工作流中获取当前日期(Dynamics CRM 2016)

How to get current date in workflows (Dynamics CRM 2016)

我想问一下如何在工作流中获取当前日期?

例如:-

我有一个名为(检验日期)的字段,我想比较这个字段,如果它等于当前日期,然后进入流程。

我将创建等待条件,等待当前日期 = 检查日期,然后执行我的流程。

如何在工作流中获取当前日期?

在 window "Specify Condition" select 字段 "Inspection Date" 中,条件 "Is Greater Than or Equal To"。在表单助手中展开选择列表 "Look for","Local Values" 下的 select 选项 "Process"。在选择列表下方的框中显示 "Execution Time"。 Select 它和你完成了。

要回答 OP 关于如何在工作流中获取当前日期的问题,简短的回答是你不能。正如 Henk van Boeijen 所描述的,可以在某些单独的步骤中获取当前日期。

在我工作的地方,我们实施了一个非常基本的自定义工作流 activity,它只是 returns 当前日期和时间。

public class CurrentDateWorkflow : CodeActivity
{
    protected override void Execute(CodeActivityContext executionContext)
    {
        try
        {
            // Create the context and tracing service
            IExecutionContext context = executionContext.GetExtension<IExecutionContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            ITracingService tracingService = executionContext.GetExtension<ITracingService>();
            if (tracingService == null)
                throw new InvalidPluginExecutionException("Failed to retrieve tracing service.");

            tracingService.Trace("Entered CurrentDateWorkflow.Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}",
                executionContext.ActivityInstanceId,
                executionContext.WorkflowInstanceId);

            var DatePartOnly = InputDatePartOnly.Get(executionContext);

            // Set output parameters
            if (DatePartOnly)
                CurrentDate.Set(executionContext, DateTime.UtcNow.Date);
            else
                CurrentDate.Set(executionContext, DateTime.UtcNow);

            // All done
            tracingService.Trace("CurrentDateWorkflow.Execute() Complete. Activity Instance Id: {0}, Workflow Instance Id: {1}",
                executionContext.ActivityInstanceId,
                executionContext.WorkflowInstanceId);
        }
        catch (Exception ex)
        {
            throw new InvalidPluginExecutionException(String.Format("An error occurred in the {0} plug-in.",
                    this.GetType().ToString()),
                    ex);
        }
    }

    [Output("Current Date")]
    public OutArgument<DateTime> CurrentDate { get; set; }

    [Input("Date Only")]
    [Default("False")]
    public InArgument<bool> InputDatePartOnly { get; set; }
}