Task not triggered

Dear all,
I cannot trigger a task, my tasks.js seems to be the problem.

I am running a form at a place. The form-id is young_infant.
It has a calculate field d_after_lab_task, that generates a number.
If d_after_lab_task is equal to 1 I want the tast to be triggered.

The task would start another form with the form-id young_infant_afterlab, again at the facility level, at the same facility.

I run the flow but no task is triggered.

The relevant part of my task.jsfile is

{
    name: 'young_infant_afterlab',
    icon: 'icon-followup-general',
    title: 'YI continue after lab',
    appliesTo: 'reports',
    appliesToType: ['young_infant'],
    appliesIf: function(contact, report) {
      return report && getField(report, 'd_after_lab_task') === '1';
    },
    actions: [
      {
        type: 'report',
        form: 'young_infant_afterlab',
        modifyContent: function (content, contact, report) {
          content.d_vsd = getField(report, 'd_vsd');
          content.d_malaria_severe = getField(report, 'd_malaria_severe');
          content.d_infection_syphilis_unlikely = getField(report, 'd_infection_syphilis_unlikely');
          content.d_delay_developmental_suspected = getField(report, 'd_delay_developmental_suspected');
        }
      }
    ],
    events: [
      {
        id: 'young_infant_afterlab',
        days: 0,
        start: 2,
        end: 7
      }
    ],
    resolvedIf: function(contact, report, event, dueDate) {
      const startTime = Math.max(addDays(dueDate, -event.start).getTime(), report.reported_date);
      const endTime = addDays(dueDate, event.end + 1).getTime();
      return isFormArraySubmittedInWindow(
        contact.reports, ['young_infant_afterlab'], startTime, endTime
      );
    }
  },

I have checked the reports, the trigger variable is 1, so it is not a problem with the initial form.

Hello @raf

There are several reasons a task might not (appear to not) trigger:

  1. appliesIf returns false
  2. resolvedIf returns true
  3. Task is not visible yet according to the window period defined in events

Please read through the frequently asked questions on tasks for more details on the same and debugging task rules.

Writing tests using the CHT test harness will save you hours of debugging/maintenance/regression testing time.

Let us know how it goes.

If all that @kitsao has pointed out is okay then you may need to check that the path you are giving to your function getField is correct, remember that if your field path is for example report.infant_assessment.young_infant.d_after_lab_task then you should do getField(report, 'young_infant.d_after_lab_task') instead of getField(report, 'd_after_lab_task').