Hello all,
I'm having trouble referencing a particular date from a particular instance of a repeating form in a datediff() function.
Here's what it looks like:
datediff([randomisation_arm_1][ra_rand_dt], [treatment_arm_1][ts_last_treatment_sess_dt][aggregate-max:ts_last_treatment_sess_in:record-name], 'd')
... where [aggregate-max:ts_last_treatment_sess_in:record-name] is a smart variable that gets me the instance I need - on it's own it works fine and brings back the instance number I expect. So that's not the problem.
When I stick it in the datediff() function in the above format, it doesn't work. And I'm not really surprised by that, cos I guess it's coming out as ...
[treatment_arm_1][ts_last_treatment_sess_dt]instance_number
...when REDCap expects...
[treatment_arm_1][ts_last_treatment_sess_dt][instance_number]
So I tried using the concat() function to put the square brackets around it, like so ...
datediff([randomisation_arm_1][ra_rand_dt], concat("[treatment_arm_1][ts_last_treatment_sess_dt][",
[aggregate-max:ts_last_treatment_sess_in:record-name], "]"), 'd')
... but that didn't work either.
If I stick just this part...
concat("[treatment_arm_1][ts_last_treatment_sess_dt][",
[aggregate-max:ts_last_treatment_sess_in:record-name], "]")
... into a @CALCTEXT field, it comes out like this...
document.form.ts_last_treatment_sess_dt.valuedocument.form.treatment_arm_1.value[document.form.treatment_arm_1.value14]
I've tried swapping out thew square brackets for HTML entities or unicode equivalents, but no cigar.
I tried it with round brackets instead of square ones and it works fine, so something about those square brackets throws it for a wobbly.
I just wondered if anyone had come across this before?
Thanks,
David.