# "Error fetching tasks" - Tasks not appearing

**URL:** <https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537>\
**Category:** Technical Support\
**Tags:** tasks, web-app\
**Created:** [January 6, 2020, 8:53am UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537 "2020-01-06T08:53:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamor](https://communityhealthtoolkit.b-cdn.net/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@Tamor](https://forum.communityhealthtoolkit.org/u/Tamor)\
**Post date:** [January 6, 2020, 8:53am UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/1 "2020-01-06T08:53:49Z")

</div>

Hi!

I am not able to see any tasks, neither built-in default tasks as well as the ones I made myself.  
For example I filled delivery form and choose alive and unwell in this form so it should initiate task to fill the form: pnc-danger-sign-follow-up-mother but that’s not happening. Also I made two forms of my own and tried to create task which opens another form when one is finished and it failed too.

I tried to debug inserting console.log() to tasks.js in different kind of tasks, but in console I could not not see any of my logs. I enabled debug mode in app and gave all the permissions to every role as it was suggested in documentation.

Maybe it is helpful that in console there is a following error displayed:

 ![image](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/1X/bba7e08452985da66e34587e4accde14b1cb8279.png)

Thank you for any advice!

- Instance: local
- Browser: Chrome
- Client platform: Windows subsystem Ubuntu
- App: webapp
- Version: 3.7.0, master

Regards  
Tamor

---

<div class="post-metadata">

**Author:** ![binod](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/binod/32/60_2.png) [@binod](https://forum.communityhealthtoolkit.org/u/binod)\
**Post date:** [January 6, 2020, 5:58pm UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/2 "2020-01-06T17:58:28Z")

</div>

Hi Tamor,

The tasks are probably not showing up because of the error shown in the console.  
Thanks for attaching the console error. Looks like your task is expecting some object with `type` attribute in it. But the object itself is in an `undefined` state, that is never set. It could be getting a non-existent/malformed report or contact. Reports generally have `type = data_record`, whereas contacts can be one of the types: `person`, `clinic`, `health_center`, `district_hospital`, or anything else defined as a place type.

As you have mentioned, you have added two forms of your own and tried to create a task. When you remove the extra reports (no need to remove the forms), and extra task logic that you have added, do you still see the same error in the console?

The `console.log()` should work. Can you please try again by inserting it at the first line of your `tasks.js`? You might also find [`debugger;` statement](https://www.w3schools.com/jsref/jsref_debugger.asp) useful.

Thanks

---

<div class="post-metadata">

**Author:** ![Tamor](https://communityhealthtoolkit.b-cdn.net/letter_avatar_proxy/v4/letter/t/258eb7/32.png) [@Tamor](https://forum.communityhealthtoolkit.org/u/Tamor)\
**Post date:** [January 14, 2020, 8:47pm UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/3 "2020-01-14T20:47:48Z")

</div>

Thank you for the quick answer!

You were right that application starts to work properly when I remove extra reports.

I checked from database and my report has the type data\_record. I do not believe that any parameter could be wrong or missing for data records since they look similar to working data records.

I tried this: I made an exact copy of death\_report and uploaded it as death\_report2 but the application continued to malfunctione as before so it seems that the mistake is somewhere else than in my form. I also used only default tasks and targets.

I did not mention before, that targets also stop working when I fill new selfmade report. It just displays loading image.

In console there were various other errors and they occurred quite randomly, for example:

- Error getting tasks TypeError: Cannot read property ‘dueDate’ of undefined
- Error fetching targets TypeError: Cannot read property ‘dueDate’ of undefined
- tasks.resolvedIf is not a function etc

I still struggle with getting those tasks working so I appreciate any help.

---

<div class="post-metadata">

**Author:** ![binod](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/binod/32/60_2.png) [@binod](https://forum.communityhealthtoolkit.org/u/binod)\
**Post date:** [January 16, 2020, 6:54pm UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/4 "2020-01-16T18:54:45Z")

</div>

Hi Tamor,

When making a copy of `death_report` as `death_report2`, did you also change the `form_id` in `settings` tab of the XLS form?

Thanks

---

<div class="post-metadata">

**Author:** ![cliff](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/cliff/32/1638_2.png) [@cliff](https://forum.communityhealthtoolkit.org/u/cliff)\
**Post date:** [August 24, 2023, 12:35pm UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/5 "2023-08-24T12:35:00Z")

</div>

hello @binod @jkuester

i have configured a task to appear when a `blood draw appointment` option is select on the appointment of a particular patient as seen below

```auto
{
    name: 'blood-appointment-reminder-task',
    title: 'Blood draw Appointment Reminder',
    icon: 'assessment',
    appliesTo: 'reports',
    appliesToType: ['appointment'],
    appliesIf: function(c, r){
      return r.fields.appoint.type_appoint === 'blood draw appointment';
      
    },
    // the form_id of the form to appear in the tasks tab
    actions: [{ form: 'blood_draw_appointment_reminder', 
 
   }],
    events: [{
      start: 1,
      end: 1,
      dueDate: function (event, contact, r) {
        return Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0);
      }
    }],
    resolvedIf: function(c, r, event, dueDate) {
      // Resolved if there is a reminder received in time window
      return isFormFromArraySubmittedInWindow(c.reports, 'reminder',
                 Utils.addDate(dueDate, -event.start).getTime(),
                 Utils.addDate(dueDate, event.end+1).getTime());
    },
  },

```

Below is a payload doc sample of the appointment form filled out on a patient

```auto
{
 "id": "8de6f865-9ee0-4c0b-b000-ea853ddbb70c",
 "key": [
  "appointment",
  "745e0796-3bd3-4df5-aade-fd4f1d1840d2"
 ],
 "value": 1692879479601,
 "doc": {
  "_id": "7de6f865-9ee0-4c0b-b000-ea873ddbb70c",
  "_rev": "1-6dbf73cf81b5b36212fa3f48a86629d8",
  "form": "appointment",
  "type": "data_record",
  "content_type": "xml",
  "reported_date": 1692879479601,
  "contact": {
   "_id": "1868ba20-6b1c-4323-b0fe-99d9261338ae",
   "parent": {
    "_id": "745e0796-3bd3-4df5-aade-fd4f1d1840d2"
   }
  },
  "from": "+256785579890",
  "form_version": {
   "time": 1692564086680,
   "sha256": "8d5e16f69eb30ec5b5030daf54bb5588ca7aa78eb2e8fb6a72bbaa688594474b"
  },
  "hidden_fields": [
   "meta"
  ],
  "fields": {
   "inputs": {
    "meta": {
     "location": {
      "lat": "",
      "long": "",
      "error": "",
      "message": ""
     },
     "deprecatedID": ""
    },
    "source": "contact",
    "source_id": "",
    "contact": {
     "_id": "b0d90405-8390-4dcc-9c35-a93d07b161b9",
     "patient_id": "65444",
     "name": "Jevon Test",
     "date_of_birth": "2022-12-01",
     "sex": "",
     "name1": "Test",
     "aka": "",
     "tsis": "5",
     "at": "male",
     "genda": "gender_male",
     "parent": {
      "contact": {
       "phone": "+256785579890",
       "name": "Cliff Test"
      }
     }
    }
   },
   "patient_id": "65444",
   "patient_name": "Jevon Test",
   "patient_name1": "Test",
   "patient_aka": "",
   "patient_tsis": "5",
   "patient_genda": "gender_male",
   "patient_at": "male",
   "patient_date_of_birth": "2022-12-01",
   "fast_name_ctx": "Jevon Test",
   "last_name_ctx": "",
   "date_of_birth_ctx": "2022-12-01",
   "aka_ctx": "",
   "tsis_ctx": "5",
   "at_ctx": "male",
   "yr_date_of_birth_ctx": "1",
   "gender_ctx": "gender_male",
   "appoint": {
    "first_name": "",
    "nick": "",
    "age_n": "",
    "gender_n": "",
    "dob": "",
    "n_special_instruction_title": "",
    "complete": "hjhhjhjh",
    "type_appoint": "blood draw appointment",
    "welcome": "",
    "lab_test": "viral load",
    "date_appoint1": "2023-08-25"
   },
   "meta": {
    "instanceID": "uuid:aa57273c-50a0-48b1-a4c2-7084c3e5474a"
   }
  },
  "geolocation_log": [
   {
    "timestamp": 1692879479608,
    "recording": {
     "code": 1,
     "message": "User denied Geolocation"
    }
   }
  ],
  "geolocation": {
   "code": 1,
   "message": "User denied Geolocation"
  },
  "_attachments": {
   "content": {
    "content_type": "application/xml",
    "revpos": 1,
    "digest": "md5-pFb/YFC3kH0SNGfxZlKP8Q==",
    "length": 2379,
    "stub": true
   }
  }
 }
}

```

Not sure why the `Blood draw Appointment Reminder` task is still not appearing in the tasks tab

---

<div class="post-metadata">

**Author:** ![jkuester](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/jkuester/32/806_2.png) [@jkuester](https://forum.communityhealthtoolkit.org/u/jkuester)\
**Post date:** [August 25, 2023, 2:06pm UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/6 "2023-08-25T14:06:39Z")

</div>

@cliff I tried to recreate the issue with your task config here, but it seems to work as expected for me!

Maybe you could add some `console.log` statements to the functions in your task config block and try printing some of the values you are getting to double-check the logic. Then on the browser open the Tasks tab and check the browser logs for your messages (and/or any other errors).

---

<div class="post-metadata">

**Author:** ![cliff](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/cliff/32/1638_2.png) [@cliff](https://forum.communityhealthtoolkit.org/u/cliff)\
**Post date:** [August 28, 2023, 7:36am UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/7 "2023-08-28T07:36:48Z")

</div>

> [@jkuester](#):
>
> Maybe you could add some `console.log` statements to the functions in your task config block and try printing some of the values you are getting to double-check the logic. Then on the browser open the Tasks tab and check the browser logs for your messages (and/or any other errors).

hello @jkuester  
i have logged to the console the task triggering logic

```auto
 {
    name: 'blood-appointment-reminder-task',
    title: 'Blood draw Appointment Reminder',
    icon: 'assessment',
    appliesTo: 'reports',
    appliesToType: ['appointment'],
    appliesIf: function(c, r){

      console.log( r.fields.appoint.type_appoint);
      return r.fields.appoint.type_appoint === 'blood draw appointment';
      
    },
    actions: [{ form: 'blood_draw_appointment_reminder', 
  
   }],
    events: [{
      start: 1,
      end: 1,
      dueDate: function (event, contact, r) {
        return Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0);
      }
    }],
    resolvedIf: function(c, r, event, dueDate) {
      // Resolved if there is a reminder received in time window
      return isFormFromArraySubmittedInWindow(c.reports, 'reminder',
                 Utils.addDate(dueDate, -event.start).getTime(),
                 Utils.addDate(dueDate, event.end+1).getTime());
    },
  },

```

and it displays the desired results

 ![Screenshot 2023-08-28 at 10.23.30 AM](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/7/75722702abb29cc30c6dddfbd2ff1c15340d7400.jpeg)

---

<div class="post-metadata">

**Author:** ![jkuester](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/jkuester/32/806_2.png) [@jkuester](https://forum.communityhealthtoolkit.org/u/jkuester)\
**Post date:** [August 29, 2023, 1:45pm UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/8 "2023-08-29T13:45:45Z")

</div>

Okay, so this is a start! We know your task config has been successfully deployed and is being recognized:

- ☑︎ `appliesTo`
- ☑︎ `appliesToType`
- ☑︎ `appliesIf`
- ☐ `actions`
- ☐ `events`
- ☐ `resolvedIf`

The next thing to check is the `events`. In your `appliesIf` function, can you also log out `Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0)` and see what value that gives you? Task visibility is going to be determined by the `dueDate` so we want to be sure that is what we expect. Also, now is a good time to double-check your `resolvedIf`. In this case, you want to look for any existing `reminder` reports for the contact with a `reported_date` that is near the `dueDate`. (Remember that the `reminder` reports found by the `resolvedIf` function do not have to be created _after_ the initial `appointment` report that triggers the task. Existing `reminder` reports can suppress the creation of new instances of `blood-appointment-reminder-task`.)

---

<div class="post-metadata">

**Author:** ![cliff](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/cliff/32/1638_2.png) [@cliff](https://forum.communityhealthtoolkit.org/u/cliff)\
**Post date:** [August 29, 2023, 2:48pm UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/9 "2023-08-29T14:48:47Z")

</div>

> [@jkuester](#):
>
> The next thing to check is the `events`. In your `appliesIf` function, can you also log out `Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0)` and see what value that gives you? Task visibility is going to be determined by the `dueDate` so we want to be sure that is what we expect.

hello @jkuester

the inspecting feedback of the due date from the browser shows an` invalid date`

 ![Screenshot 2023-08-29 at 5.46.55 PM](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/a/a3e7b9453c8f633725b170c154b49d8a620e80d1.jpeg)

---

<div class="post-metadata">

**Author:** ![cliff](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/cliff/32/1638_2.png) [@cliff](https://forum.communityhealthtoolkit.org/u/cliff)\
**Post date:** [August 29, 2023, 4:39pm UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/10 "2023-08-29T16:39:08Z")

</div>

@jkuester the tricky bit is that for another `Appointment Reminder` task configuration, the due date is captured as seen below

```auto
{
    name: 'appointment-reminder-task',
    title: 'Appointment Reminder',
    icon: 'assessment',
    appliesTo: 'reports',
    appliesToType: ['appointment'],
    appliesIf: function(c, r){
      return r.fields.appoint.type_appoint === 'clinical appointment' 
    },
    actions: [{ form: 'appointment_reminder', 
   }],
    events: [{
      start: 1,
      end: 1,
      dueDate: function (event, contact, r) {
      /console.log(Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0));

        return Utils.addDate(new Date(getField(r, 'appoint.date_appoint')), 0);
      }
    }],
    resolvedIf: function(c, r, event, dueDate) {
      // Resolved if there is a reminder received in time window
      return isFormFromArraySubmittedInWindow(c.reports, 'reminder',
                 Utils.addDate(dueDate, -event.start).getTime(),
                 Utils.addDate(dueDate, event.end+1).getTime());
    },
  },

```

 ![Screenshot 2023-08-29 at 7.37.10 PM](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/c/cad2a93a6f4ad4fa4ee6afea24ab5c8e57104394.jpeg)

---

<div class="post-metadata">

**Author:** ![jkuester](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/jkuester/32/806_2.png) [@jkuester](https://forum.communityhealthtoolkit.org/u/jkuester)\
**Post date:** [August 29, 2023, 5:54pm UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/11 "2023-08-29T17:54:22Z")

</div>

> the inspecting feedback of the due date from the browser shows an` invalid date`

Definitely seems like it is not able to load the date from the report.

> the tricky bit is that for another `Appointment Reminder` task configuration, the due date is captured

This was a very interesting to me since the task configs are basically identical. That made me go back and have a much closer look at the doc JSON in your original post. It was then that I noticed that in the JSON, your `appoint.date_appoint` field _is actually named_ `date_appoint1`!!! Can you double-check this name in your form config? Our trouble here might be as simple as a naming mismatch between the form field and the task config…

---

<div class="post-metadata">

**Author:** ![cliff](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/cliff/32/1638_2.png) [@cliff](https://forum.communityhealthtoolkit.org/u/cliff)\
**Post date:** [August 29, 2023, 6:11pm UTC](https://forum.communityhealthtoolkit.org/t/error-fetching-tasks-tasks-not-appearing/537/12 "2023-08-29T18:11:07Z")

</div>

> [@jkuester](#):
>
> This was a very interesting to me since the task configs are basically identical. That made me go back and have a much closer look at the doc JSON in your original post. It was then that I noticed that in the JSON, your `appoint.date_appoint` field _is actually named_ `date_appoint1`!!! Can you double-check this name in your form config? Our trouble here might be as simple as a naming mismatch between the form field and the task config…

@jkuester yeah you are right its the same issue i have discovered while i was do some more debuggings 🙂

 ![Screenshot 2023-08-29 at 9.07.55 PM](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/0/0c6f6fcd4240596aadc09c446064eee7917136d8.jpeg)

it works fine now

thanks a bunch for your time 💯
