Target date not found in work calendar

“Target date not found in work calendar” was an error that was reported to me by a customer using workflow in AX2009. It was easy to find that it was thrown by WorkflowWorkCalendarDueDateProvider.isWorkingDay() but it was far from obvious why.

I tried to update the calendar in approval time limit, although it didn’t seem to be used in that moment (but it did automatically default to a calendar for a previous year):

ApprovalTimeLimit

This seemed to be the core problem – the calendar contained dates for a single year only and anything outside that year caused an error (because, as the error message correctly said, the target date was not found in work calendar).

Changing the calendar helped a little bit, but the workflow failed with the same error a moment later. I found that the calendar ID was saved in every single workflow step (WorkflowStepTable.Duration):

PackedWorkflowStep

 

It seems to me that:

  1. A calendar used in workflow should cover all possible dates (we can add additional dates to the calendar when needed, but we won’t have to ever change the reference to calendar).
  2. If it needs to be changed, the workflow configuration should be dropped and set up again.
  3. But it’s of course possible to update all workflow steps from code:
WorkflowStepTable   step;
WorkflowConfigDate  confDate;
str                 newCalendarId = 'Workflow';
;
ttsbegin;
 
while select forUpdate step
{
    confDate = WorkflowConfigDate::create(step.Duration);
    confDate.parmDailyCalendar(newCalendarId);
    confDate.parmHourCalendar(newCalendarId);
    step.Duration = confDate.pack();
    step.update();
}
 
ttscommit;

2 Comments

Leave a Reply

Your email address will not be published.