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));
}
[Input("string")]
[Default("10/11/2010")]
public InArgument StringInput { get; set; }
[Output("Date")]
[Default("01/01/01")]
public OutArgument DateOutput { get; set; }
}
}
Call the assembly and pass the date string and use the return value to set the date field as shown in screen shots below.
it's a good solution but one word of warning it won't word on CRM online because you can't have custom workflows
ReplyDeleteI try and compile this but get an error :-
ReplyDeleteThe type arguments for method 'System.Activities.ActivityContext.GetExtension()' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Mark,
ReplyDeleteI 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);
Hello -
ReplyDeleteI 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?
Thanks.
ouch...
ReplyDeleteIt was a problem with the blogspot rendering. it was hiding everything between < > . I have updated the code again.
Good luck.