Can ODK generate unique codes based on codes from a dropdown list?

Hello!

I'm conducting a survey to collect geographical coordinates for different cotton fields, along with other questions related to each specific field. Before providing this information, users will see a list with their identification code and name, followed by a question about the number of fields they will register. I have used the repeat question feature for cases where each user has up to one field. Since each field is unique,

Can ODK generate unique codes for each field based on the user’s code? For example, if the user code is IML1234, the code for the first field would be IML1234-001.

Could you share a related extract of your form (and choice list), please?

Hi!! Do you mean this way...?

Test the form here: https://staging.enketo.getodk.org/preview?form=https%3A//staging.xlsform.getodk.org/downloads/842e14cbfdbf45f1bafe68e577157bf6qcu6txbp/test0101.xml

I have also attached the definition for the form.
test0101.xlsx (9.8 KB)

3 Likes

Hi,

Thank you for your answer! MinimalPotato has answered and sent me the definition form and it is exactly what I was looking for! Thanks a tons

Hey,

This is exactly what I was looking for. This is great! I really appreciate all your help and support on this. Thanks a tons!!!!!! :slight_smile:

1 Like

You're most welcome! :smile:

1 Like

Note, because this code only accommodates a single '0' or double '00' prefix - that is, only numbers between 0..999 are supported - you might also consider explicitly limiting the number of entries accordingly [not that anybody really wants to swipe thru 1000+ repeat group iterations...]

concat(${int_code}," - ",if(string-length(string(position(..)))=3,string(position(..)),if(string-length(string(position(..)))=2,concat("0",string(position(..))),if(string-length(string(position(..)))=1,concat("00",string(position(..))),""))))

that is, add:

fields: constraint = '.>0 and .<=999'

[btw, love your pseudonym! :laughing:]

3 Likes

Hi Xiphware, thank you so much for this note. I agree! I will take this in count. Thanks a tons everyone!!