Displaying data from a previously submitted form

Hello @diana @samuel

Is it possible to display data from a previously submitted form as a label in the new task form being filled out as a follow up for example if i feel out a check box field in form A and submit it, and i want to display some of the results in that submitted form as a label in the next follow up task form B

Yes this should be possible. You can read some more details in the task documentation, but I think the basic workflow would look like this:

  • In your task definition (for the task triggered by submitting form A) you would want to set your desired value from form A to the content for the newly triggered form B using the modifyContent function:

    modifyContent: function (content, contact, report, event) {
      content.my_field = getField(report, 'my_field');
  • Then in form B, you would need to define a hidden field named my_field within the inputs group. When this form is triggered by a task, this field will be automatically populated with data from the task.

  • Finally, your label in form B just needs to reference the hidden field in the label text: My field: ${my_field}

You can find more examples of using the modifyContent functionality in the sample config here: cht-core/config at master · medic/cht-core · GitHub

1 Like

hello @jkuester @diana

Is it possible to display data from a previously submitted form outside of the task and modifyContent: function configuration ?

Hi @cliff

Could you please elaborate? What does “outside of the task” refer to? Is there a reason why modifyContent is not suitable for your use case?


thanks @diana
I mean for example if am pulling data ie date of birth or phone number from the enrollment entry form of a patient and displaying it as labels in another form that i don’t intend to configure for a task

Hi @cliff

Thanks for the detailed explanation.
I believe you can populate a form with some outside data if you leverage contact-summary and submit a form for a contact.

First you would change your contact summary function to return some fields that are relevant, for example, pulling date of birth or phone number from the enrollment entry and adding them as fields.
Then, in another form, add a contact-summary instance and reference it to display or calculate fields:

Submitting this form from the contact page enables the contact-summary data to be passed directly into the form.


thanks @diana ,

hello @diana made some changes with the approach above ie

i added a contact summary calculation as seen below

and then referenced it later on

Then modified the context in the contact summary card

modifyContext: function(ctx, report) {
      let fst_name = getField(report, 'contact:person:create.person.name');
      ctx.fstname = fst_name;

where contact:person:create is the form id of the enrollment form for a new patient .
The First name entered in the enrollment form is not displaying in the other form , could i have missed something here ?
cc @jkuester

hello @diana ,
I managed to pull the patient name ie name form the enrollment form which i under the inputs section

however when i try the same approach on the date_of_birth it fails ,the approach works for _id, patient_id, name but fails for the rest

Hi @cliff

contact:person:create doesn’t generate a report, it generates a contact type document.
I think, in your case, the simplest would be to add an additional context property like:

const context = {
  alive: isAlive(thisContact),
  muted: false,
  fstname: thisContact.name,

There should be no need for modifyContext.

1 Like

thanks @diana ,works fine now