Order of Operations/Dependencies on hidden field calculations

Hi all,

I am having some issues with using hidden field references within other
hidden fields.

In my case, we have data in our cases for a day, month, and year. We need
to convert this data into a date and use it in other areas of the form to
calculate time in months from today.

Currently I am trying to do the following:

  1. Load in the case data into a separate days, months, year field
  2. Doing a concat, padding leading zeros where necessary, of the three
    fields into YYYY-MM-DD style
  3. In a different hidden field, casting the Date String from the concat
    into a real date field

When I try to load the form it executes the #3 step before years and months
have been loaded into the form causing an XPath error when converting
string to date due to the null month and year. Is there a way to specify
dependencies among hidden values or determine the order in which they
calculate? Or is there a better way to combine a day, month, year field
into a usable date field? (Should I just use a true date question? And will
it still work if we don't really want to make this a visible question?)

Any tips would be appreciated! Thanks!

-Caleb

Hello Caleb,

Date math is a tough area in general and there are a few gotchas in
CommCare to be wary of. However, I'd give this page
https://confluence.dimagi.com/display/commcarepublic/Calculations+with+Dates+and+Times
a
thorough reading because I'm pretty sure you'd be better off using a proper
date than your current arrangement. The fact that you're using the date as
a hidden value should be fine.

However if you do find your current configuration better suited to your
needs, people generally use the coalesce()
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-coalesce
function
with the target calculation first and a non-null value second to ensure
that they will never crash on a value that hasn't been set yet.

Best,
Will

ยทยทยท On Mon, Oct 5, 2015 at 2:20 PM, wrote:

Hi all,

I am having some issues with using hidden field references within other
hidden fields.

In my case, we have data in our cases for a day, month, and year. We need
to convert this data into a date and use it in other areas of the form to
calculate time in months from today.

Currently I am trying to do the following:

  1. Load in the case data into a separate days, months, year field
  2. Doing a concat, padding leading zeros where necessary, of the three
    fields into YYYY-MM-DD style
  3. In a different hidden field, casting the Date String from the
    concat into a real date field

When I try to load the form it executes the #3 step before years and
months have been loaded into the form causing an XPath error when
converting string to date due to the null month and year. Is there a way to
specify dependencies among hidden values or determine the order in which
they calculate? Or is there a better way to combine a day, month, year
field into a usable date field? (Should I just use a true date question?
And will it still work if we don't really want to make this a visible
question?)

Any tips would be appreciated! Thanks!

-Caleb

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.