Is it possible to set the value of a field based on a subset of another field value? e.g. I have a national ID number that has the date of birth in the first 6 digits:
7410237098108
In the above, we can glean the date of birth as 23 October 1974 (741023). Would it be possible to set the value of a date of birth field when the user enters the full ID into the national ID field?
Interesting question… I think it might be possible to use program rules for this case because it doesn’t wait for anything to be exported i.e. the value is available in another filed in the form.
If you’re willing to experiment. I’m thinking of something such as
d2:concatenate(d2:substring(dateOfBirth, 2, 4), d2:substring(dateOfBirth, 5, 7), d2:substring(dateOfBirth, 8, 10))
If the date of birth format is yyyyMMdd (19741023) and if substring will be able to recognize it as a string… I think the expression above should work. Would you give it a try and share how it goes?
Thanks!
Thanks for the feedback! I’ll be able to confirm later today or before the end of this week at the latest.
Thanks! I’m hoping it worked or you might have found a better way?
Thanks for the feedback, I think for now we’re not going to implement this as validation becomes an issue. I’m not sure how we would go about firstly validating the ID to ensure the first 6 digits are indeed a valid yymmdd value before we populate the DOB field.
Thanks @Edward_Robinson ! Isn’t the DoB being filled out first? So you’d need to first validate the DoB?
Unfortunately not, we’re trying to parse the date of birth from the ID number. What we might do is validate the DOB based on the ID which will help with QA.
Maybe you could simply extract the first two numbers (yy) and check that they are within a possible range (less than 64 and greater than 24) [assuming the oldest person would be 160?] then check the second two numbers to be greater than 0 and less than 13, and then check that the day is not greater than 31 and not less than 1. This way, it’s more possible it’s a date.
Thanks, that’s a great suggestion. We’ll also test to see what happens if an invalid date is entered (e.g. 30th Feb).