Create Task based on manually entered date

FLHW user creates the patient .
FLHW fills 2 form for one patient i.e( Enrollment form & Follow up form)

After FLHW fills the first form of patient i.e Enrollment form .
Enrollment form has a question where next visit date is filled manually.

Based on manually entered next visit date on Enrollment form , A new task should be created(i.e follow-up form ).

Hi @Sanjit7,

It looks like you want to specify the due date for a task using a date field on the source report.
For that, you can use dueDate instead of days in the events.

Here is the reference document you can follow to understand how to use dueDate:

Here are some examples of dueDate being used in tasks:

  1. Tutorial:
    Building A Complex Task (Optional) | Community Health Toolkit

  2. Default config:

Got error while creating task

module.exports = [
    name: 'follow_up',
    title: 'task.followup.title',
    appliesTo: 'reports',
    appliesToType: ['enrollment_form'],
    appliesIf: function (contact, report) {
      const SBP = Utils.getField(report, 'g3_bp_measurement.q20_sbp');  
      const DBP = Utils.getField(report, 'g3_bp_measurement.q21_dbp');
      return SBP >= 140 || DBP >= 90;
    actions: [
        form: 'follow_up'
    events: [
        id: 'follow-up-event-id',
        start: 0,
        end: 1,
        dueDate: function (event, contact, report) {
          const nextVisitDate = Utils.getField(report, 'g4.q36_next_visit_date');
          return Utils.addDate(nextVisitDate);
    resolvedIf: function (contact, report, event, dueDate) {
      return Utils.isFormSubmittedInWindow(
        Utils.addDate(dueDate, -event.start).getTime(),
        Utils.addDate(dueDate, event.end + 1).getTime()


Error code

dueDate@ line 1 > Function:3:1944
p@ line 1 > Function:3:6294
a@ line 1 > Function:3:6073
anonymous/</e.exports@ line 1 > Function:3:7637
anonymous/<@ line 1 > Function:3:1456
o@ line 1 > Function:3:110
anonymous/<@ line 1 > Function:3:902
anonymous@ line 1 > Function:3:911

It looks like CHT has encountered a problem when running the Utils.addDate function.

Although it might not be the cause of the error above, the function requires two arguments:

  1. a date to start with
  2. the number of days to add

You are providing only the first argument i.e. nextVisitDate.
Also, please make sure that nextVisitDate is a valid JS Date.
You are probably getting a string from the report in a format similar to 2023-11-28. You need to convert it into JS date:

const nextVisitDate = Utils.getField(report, 'g4.q36_next_visit_date');
//optional: check in browser log that you are getting the correct date
console.log('next visit': nextVisitDate); //remove later
const nextVisitDateJS = new Date(nextVisitDate);
return nextVisitDateJS;

You might have more details about the error in the browser console. Please check.