I had an issue with a Workflow that was retrieving a DateTime from a plugin and updating the entity. The problem was the DateTime being updated wasn't correct. I've created an example to demonstrate the problem.
I have a test entity with two DateTime fields and a String field. One DateTime field is TimeZone Indenpendt, the other is User Local. I run an on-demand workflow that gets the current DateTime and returns it in DateTime and String format.
public class WorkflowTimingTest : ActivityBase { [Output("Time")] public OutArgument<DateTime> Time { get; set; } [Output("Time String")] public OutArgument<string> TimeString { get; set; } public override void Execute(CodeActivityContext context, LocalContext localContext) { DateTime dtm = DateTime.Now; TimeString.Set(context, dtm.ToString()); Time.Set(context, dtm)); } }
The Workflow simply updates the Test entity.
When I run this Workflow and update the record, this is what I see.
As you can see, the plug-in itself didn't acknowledge that I used DateTime.Now (Not UTC Now, which I've tried to use and provides the same outcome). The CRM also didn't convert the time to local, leaving both times as GMT. (We're in EST currently observing DST at -4 GMT).
Can someone explain this? I need to be able to return a specific time from a workflow, this doesn't seem possible without manually subtracting 4 hours (and then changing this to manually subtract 5 hours when DST ends).
*This post is locked for comments