I have a custom workflow activity. The purpose of this workflow activity is take a DateTime value as input, and output the date only portion of that DateTime. Here is the code:
namespace WorkflowFormatDateOnlyFromDateTime { public class WorkflowFormatDateOnlyFromDateTime : CodeActivity { //Set input parameter [RequiredArgument] [Input("Date Time value")] //[Default(null)] public InArgument<DateTime> dateTimeValue { get; } [Output("Date Only Equivalent")] [Default("")] public OutArgument<string> dateOnlyValue { get; set; } //Main procedure protected override void Execute(CodeActivityContext context) { //Create a tracing service for debugging purposes ITracingService tracingService = context.GetExtension<ITracingService>(); tracingService.Trace("Starting workflow activity to get Date Only from DateTime field."); //Get the workflow context from the CodeActivity context IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>(); //Create an organization service tracingService.Trace("Getting Organization Service Factory object."); IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>(); tracingService.Trace("Creating Organization Service."); IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId); //Get the date only from a DateTime field *****DateTime TempDateTime = dateTimeValue.Get(context);***** tracingService.Trace("Date Time is " + TempDateTime.ToString()); string TempDateOnly = TempDateTime.ToString("mm/dd/yyyy"); tracingService.Trace("Temp date only is " + TempDateOnly); dateOnlyValue.Set(context, TempDateOnly); } } }
On the line enclosed in asterisks (DateTime TempDateTime = dateTimeValue.Get(context);) I am getting the following error at runtime:
System.NullReferenceException: Object reference not set to an instance of an object.
This would ordinarily make me think that something is coming in as null. The input argument is being fed from a DateTime field in CRM that is, in fact, filled in. I would not think anything should be in a null state here.