Adding form field outside of fields section

How do I add a particular field which is input from user, but outside of regular fields field in document. Currently, all user inputs in CHT are captured inside the fields section in document. Some fields like form, reported_date, etc are written outside of fields field, however they are created by CHT. I need to have lmp_date field written outside of the fields form for our requriement. How can I achieve that ?

Hi @yuv

I believe it’s not possible at the moment. I had a quick look in the code, maybe @jkuester can correct me if I’m missing something.

Can you tell us more details about that requirement? Why it’s needed?

1 Like

Hi @Jennifer_Quesada,

We create different Schedules using start_from property to send reminders for SMS users. We already have 6 forms that contribute to these schedules and they all depend upon the field specified in start_from and since being created from sms, that fields is directly accessible inside doc.

Now, we are giving user(s) ability to register same form via webapp as well. And, even though users submit form via webapp, we need to create same schedules that we are creating for. Now, the field we are using in start_from is not directly available when we submit form(s) from webapp and I need that field to be exposed outside of fields, so that we can directly access from doc.

Thanks for the explanation. If I’m understanding correctly that’s a transition and I can see we’re using a library called object-path (scroll to usage) to get the start_from here.

Have you tried defining the start_from with dot notation? Like this:
"start_from": "fields.lmp_date"
Maybe it works.

Just to confirm what @Jennifer_Quesada has already said, I do not know of any way to set properties from a form outside of the fields object.

Hi @jkuester , @Jennifer_Quesada , We’ve used dot notation in some other forms where required. However, for this case all of our existing forms only have the data coming in lmp_date and not in fields.lmp_date. So, even though we might be able to create schedules out of pregnancy form by using fields.lmp_date, we’d miss other 6 forms that also need to create the same schedules.

Trying to understand the scenario, @yuv can you confirm if my understandings are correct…

  1. You want to set up SMS schedules
  2. You want this schedule to be triggered by 7 different forms
  3. Some of these 7 forms are SMS forms, some are App forms
  4. All 7 forms have an lmp_date field, but they are found in different levels (the lmp_date field is nested in the fields property of app forms)
  5. It is possible to trigger these schedules from EITHER SMS forms OR App forms; but…
  6. It is not possible to use the same schedule for both SMS forms AND App forms

So the no-dev workaround would be to duplicate the schedule and have one just use lmp_date and the other use fields.lmp_date. Correct?

I assume it is not possible to use conditional logic for the start_from, correct? (for example, check for lmp_date and if you don’t find it, use fields.lmp_date)

What about extension libraries, could you use those to either create fields.lmp_date on the SMS reports or an lmp_date at the root level on app form reports?

Hi @michael , your understanding of the scenario is right.

I am also hoping to use extension-libs and I’ll follow up any question related to extension libraries in separate question.

1 Like

It was not possible with extension-libs. This problem here would be solved after Allow schedule to start with multiple fields · Issue #8633 · medic/cht-core · GitHub is released, most probably on CHT 4.5.0.

While adding form field outside of the fields section is not worked on, the underlying issue requiring this has been fixed by allowing additional parameter in start_from. This is available in 4.5.0.