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.