Calculation field produce "undefined" result

Platform: 2.0.6:

I am designing drug order form in xform 4.3.11, I want to make length of Anti-TB prescription to be calculated from TB prescription end date and TB prescription start date, I followed https://wiki.openmrs.org/display/docs/XForms+Module+Properties+Tab, but calculated field gives undefined result. If needed I will try to reproduce

@dkayiwa

While in the form designer, can you select “Save As” from the “File” menu? Then paste the contents of the saved file at pastebin.com

https://pastebin.com/FL7L9XdK

Could you point me to the field to look at?

TB_PRESC_LNGTH_CALCULATED, TB_PRESC_START_DATE and TB_PRESC_END_DATE.

Do you have a screenshot?

Try change the calculation to: (new Date(/form/obs/tb_presc_end_date/value) - new Date(/form/obs/tb_presc_start_date/value))/ (1000 * 3600 * 24)

1 Like

Thank you so much @dkayiwa, live longer your majesty.

I want to do the same for ART and other drugs in the same form but it looks like you can only calculate one field and not more than that, when I tried to calculate more fields it says too much recursion. Is there a way to do the same for more than one field in one form?.

Can i see what you have done to result into that error?

I wanted to add calculation fields to other drugs, such as art, ipt, cotrimoxazole and others e.g (new Date(/form/obs/art_presc_end_date/value) - new Date(/form/obs/art_presc_start_date/value))/ (1000 * 3600 * 24) for art, (new Date(/form/obs/cot_presc_end_date/value) - new Date(/form/obs/cot_presc_start_date/value))/ (1000 * 3600 * 24) for cotrimoxazole, (new Date(/form/obs/ipt_presc_end_date/value) - new Date(/form/obs/ipt_presc_start_date/value))/ (1000 * 3600 * 24) for ipt, as shown in the screenshot

but when I preview the form it brings this error

Can you select “Save As” from the “File” menu and paste the file contents at pastebin.com?

https://pastebin.com/tKQD03mZ

Looks like this form has some problems because I developed new form and works fine,

Good that you figured it out. :smile: