Tuesday, May 17, 2011

How to set Date fields in MSCRM 2011 Dialogs

If you are capturing a date in a dialog, it is not possible to assign that value to the crm datetime field. It can be done by creating workflow assembly.

Create a workflow assembly, which takes a string as input parameter and return date as output parameter. Here is code..
using System;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
namespace DialogDate
public class DialogDate:CodeActivity
protected override void Execute(CodeActivityContext executionContext)
// Create the context
    //IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
    //IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
    //IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
    string sdate = StringInput.Get<string>(executionContext);
    DateOutput.Set(executionContext, DateTime.Parse(sdate));
public InArgument StringInput { get; set; }
public OutArgument DateOutput { get; set; }
Register the assembly and use it in your dialog.

Call the assembly and pass the date string and use the return value to set the date field as shown in screen shots below.


  1. it's a good solution but one word of warning it won't word on CRM online because you can't have custom workflows

  2. I try and compile this but get an error :-

    The type arguments for method 'System.Activities.ActivityContext.GetExtension()' cannot be inferred from the usage. Try specifying the type arguments explicitly.

  3. Mark,

    I think some of the dll has been modified. Anyway you just need to cast the return types from some of the methods.

    Try these four lines it will work

    IWorkflowContext context = executionContext.GetExtension();
    IOrganizationServiceFactory serviceFactory = executionContext.GetExtension();
    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
    string sdate = StringInput.Get(executionContext);

  4. Hello -
    I am having the same problem as Mark is, even using the code posted above. I am using System.Activities.dll version 4.0.30319. Any suggestions on how to fix this error?

  5. ouch...
    It was a problem with the blogspot rendering. it was hiding everything between < > . I have updated the code again.

    Good luck.