Tuesday, November 03, 2009

Custom workflow action which returns current DateTime value

Here is the code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.Activities;
using Microsoft.Crm.Workflow;
using System.Workflow.ComponentModel;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;

namespace CurrentDateTimeWorkflowStep
{
[CrmWorkflowActivity("Current Date Time", "Utiles")]
public class CurrentDateTime : SequenceActivity
{
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
Value = CrmDateTime.Now;

return base.Execute(executionContext);
}

public static DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(CrmDateTime), typeof(CurrentDateTime));

[CrmOutput("Value")]
public CrmDateTime Value
{
get
{
return (CrmDateTime)base.GetValue(ValueProperty);
}
set
{
base.SetValue(ValueProperty, value);
}
}
}
}


And here is the source project and built assembly.