Age Calculation Error "xpath type mismatch exception invalid"

246
2
08-02-2020 08:12 AM
ryanEvanczyk
New Contributor III

I have a text field to collect a date of birth in mm-dd-yyyy. I then have a series of calculations to convert it to yyyy-mm-dd and turn it into a date field whereby I can then calculate a persons age. The age makes subsequent questions relevant or not (ie. is the person a minor or not). This works in my original form.

I created a new form and copy and pasted that section into the new form for the same purpose. The new form now gives me an error message:

 

Below is the sample of the xls form with the dob/age calculations:

 

I initially did the 'paste only values' and I've tried deleting the cells and then rewriting from scratch, but both had no effect. I've checked the sheet for any connections and there are none. In the original form, the dob/age calculations are within a repeat and are not in the new form, but I don't see how that would affect this.

Help!

 

RyanE

0 Kudos
2 Replies
Philip-Wilson
Esri Frequent Contributor

Hi Ryan,

It looks like this is a type mismatch error, caused by running an expression on a text field or using an answer from a previous question that is text, but trying to run a date or numeric expression on it. Calculate questions by default are text question, however if you set the bind::type, and/or bind::esri:fieldtype to the expected correct field type, the expression should work as expected.

If you are still having issues, can you please share your xlsx file.

Regards,

Phil.

ryanEvanczyk
New Contributor III

When I removed the pt_dobdate row and then changed the types in the pt_dobstring row (bind::type and bind::esri:fieldtype to esriFieldTypeDate and dateTime respectively) it worked!

Thanks for the help,

RyanE

textpt_dobDATE OF BIRTH:mm-dd-yyyy1099-99-9999
calculatept_monthmonthsubstr(${pt_dob},0,2)null
calculatept_daydaysubstr(${pt_dob},3,5)null
calculatept_yearyearsubstr(${pt_dob},6,10)null
calculatept_dobstringdobstringconcat(${pt_year},'-',${pt_month},'-',${pt_day},'T00:00:00-07:00')esriFieldTypeDatedateTime
notept_ageAGE:if(string-length(${pt_dob})=0,null,int((today()-${pt_dobstring})div(1000*24*60*60*365.25)))