# Task not triggered

**URL:** <https://forum.communityhealthtoolkit.org/t/task-not-triggered/1981>\
**Category:** Technical Support\
**Created:** [July 7, 2022, 7:41pm UTC](https://forum.communityhealthtoolkit.org/t/task-not-triggered/1981 "2022-07-07T19:41:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raf](https://communityhealthtoolkit.b-cdn.net/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@raf](https://forum.communityhealthtoolkit.org/u/raf)\
**Post date:** [July 7, 2022, 7:41pm UTC](https://forum.communityhealthtoolkit.org/t/task-not-triggered/1981/1 "2022-07-07T19:41:59Z")

</div>

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.js`file is

```auto
{
    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.

---

<div class="post-metadata">

**Author:** ![kitsao](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/kitsao/32/57_2.png) [@kitsao](https://forum.communityhealthtoolkit.org/u/kitsao)\
**Post date:** [July 8, 2022, 9:18am UTC](https://forum.communityhealthtoolkit.org/t/task-not-triggered/1981/2 "2022-07-08T09:18:24Z")

</div>

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](https://docs.communityhealthtoolkit.org/apps/tutorials/tasks-1/#frequently-asked-questions) on tasks for more details on the same and debugging task rules.

Writing tests using the [CHT test harness](http://docs.communityhealthtoolkit.org/cht-conf-test-harness/) will save you hours of debugging/maintenance/regression testing time.

Let us know how it goes.

---

<div class="post-metadata">

**Author:** ![kembo](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/kembo/32/2895_2.png) [@kembo](https://forum.communityhealthtoolkit.org/u/kembo)\
**Post date:** [November 23, 2023, 7:54pm UTC](https://forum.communityhealthtoolkit.org/t/task-not-triggered/1981/3 "2023-11-23T19:54:17Z")

</div>

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')`.
