Auto-generated Unique ID's for each repeat

Hi,

I am new to odk so bare with me if this is incredibly simple.

I am trying to assign a unique ID to each repeat based on parent information and the sequence of repeat.

To explain, attached is a simple example of repeats from XLSform. I messed with the settings part to try to assign a unique ID to each repeat by using instance_name but it simply assigns a unique ID to the overall parent form. If that makes sense.

I want each repeat to have a unique ID associated with it's data that would essentially be today_placeofdelivery_sequenceinrepeat in this example. [Sequence in repeat being (1, 2, or 3 etc.)]. That way when its exported I could look up an ID and see the info attached with it.

When I export the data, however, I do not see unique ID's for the repeat, and instead for the whole form.

Thanks,
Arram

Autogenexamp.xlsx (9.58 KB)

Hi Arram,

If you want to get the position of a repeat, use 'position(..)'

If you want to generate a truly unique ID or a repeat, use 'once(uuid())'

For both options, store the value inside a calculate field and put the
methods (e.g., position(..)) in the calculation column.

Try that and let us know how it goes,

Yaw

··· On Mon, May 22, 2017 at 5:35 AM, wrote: > Hi, > > I am new to odk so bare with me if this is incredibly simple. > > I am trying to assign a unique ID to each repeat based on parent information and the sequence of repeat. > > To explain, attached is a simple example of repeats from XLSform. I messed with the settings part to try to assign a unique ID to each repeat by using instance_name but it simply assigns a unique ID to the overall parent form. If that makes sense. > > I want each repeat to have a unique ID associated with it's data that would essentially be today_placeofdelivery_sequenceinrepeat in this example. [Sequence in repeat being (1, 2, or 3 etc.)]. That way when its exported I could look up an ID and see the info attached with it. > > When I export the data, however, I do not see unique ID's for the repeat, and instead for the whole form. > > Thanks, > Arram > > -- > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en > > --- > You received this message because you are subscribed to the Google Groups "ODK Community" group. > To unsubscribe from this group and stop receiving emails from it, send an email to opendatakit+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/d/optout.

Hi Yaw,

Thank you.

I was able to use position(..) to assign each repeat a number. I then used concat to generate a full ID for each repeat that is like

today_placeofdelivery_position(..)
05292017-PlaceX-3

However, I would like the position number to have 4 digits, with leading zeros. so it would look like:

05292017-PlaceX-0003

I tried using regex() but it wouldn't work for autogenerate numbers like the position. any other ideas?

THanks,
Arram

··· On Monday, May 22, 2017 at 6:58:20 PM UTC+1, arramno...@gmail.com wrote: > Hi, > > I am new to odk so bare with me if this is incredibly simple. > > I am trying to assign a unique ID to each repeat based on parent information and the sequence of repeat. > > To explain, attached is a simple example of repeats from XLSform. I messed with the settings part to try to assign a unique ID to each repeat by using instance_name but it simply assigns a unique ID to the overall parent form. If that makes sense. > > I want each repeat to have a unique ID associated with it's data that would essentially be today_placeofdelivery_sequenceinrepeat in this example. [Sequence in repeat being (1, 2, or 3 etc.)]. That way when its exported I could look up an ID and see the info attached with it. > > When I export the data, however, I do not see unique ID's for the repeat, and instead for the whole form. > > Thanks, > Arram

Hi Yaw,

How would you use this uuid to retrieve a specific variable's value in one
specific repeat?

I want to apply this to put a constraint that each new value (i.e. in each
new repeat) of a variable must be smaller that the previous value (i.e. in
previous repeat) of the same field.

Best regards

··· On Thursday, 25 May 2017 16:34:36 UTC+2, Yaw Anokwa wrote: > > Hi Arram, > > If you want to get the position of a repeat, use 'position(..)' > > If you want to generate a truly unique ID or a repeat, use 'once(uuid())' > > For both options, store the value inside a calculate field and put the > methods (e.g., position(..)) in the calculation column. > > Try that and let us know how it goes, > > Yaw > > On Mon, May 22, 2017 at 5:35 AM, <arramno...@gmail.com > wrote: > > Hi, > > > > I am new to odk so bare with me if this is incredibly simple. > > > > I am trying to assign a unique ID to each repeat based on parent > information and the sequence of repeat. > > > > To explain, attached is a simple example of repeats from XLSform. I > messed with the settings part to try to assign a unique ID to each repeat > by using instance_name but it simply assigns a unique ID to the overall > parent form. If that makes sense. > > > > I want each repeat to have a unique ID associated with it's data that > would essentially be today_placeofdelivery_sequenceinrepeat in this > example. [Sequence in repeat being (1, 2, or 3 etc.)]. That way when its > exported I could look up an ID and see the info attached with it. > > > > When I export the data, however, I do not see unique ID's for the > repeat, and instead for the whole form. > > > > Thanks, > > Arram > > > > -- > > -- > > Post: opend...@googlegroups.com > > Unsubscribe: opendatakit...@googlegroups.com > > Options: http://groups.google.com/group/opendatakit?hl=en > > > > --- > > You received this message because you are subscribed to the Google > Groups "ODK Community" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to opendatakit...@googlegroups.com . > > For more options, visit https://groups.google.com/d/optout. >

Hi Arram,

If you need leading zeros, then using position(..) alone won't work.
You need to build up the string yourself.

I haven't tested this, but I'd have a calculate prompt with a
calculation like this:
if(position(..) > 9, concat('00', position(..)), concat('000', position(..)))

If the number is > 9 (so 2 digits), then store '00' + the number (e.g., 0020)
If the number is < 9 (so 1 digit), then store '000' + the number (e.g., 0008)

Hope that helps,

Yaw

··· On Mon, May 29, 2017 at 5:03 AM, wrote: > On Monday, May 22, 2017 at 6:58:20 PM UTC+1, arramno...@gmail.com wrote: >> Hi, >> >> I am new to odk so bare with me if this is incredibly simple. >> >> I am trying to assign a unique ID to each repeat based on parent information and the sequence of repeat. >> >> To explain, attached is a simple example of repeats from XLSform. I messed with the settings part to try to assign a unique ID to each repeat by using instance_name but it simply assigns a unique ID to the overall parent form. If that makes sense. >> >> I want each repeat to have a unique ID associated with it's data that would essentially be today_placeofdelivery_sequenceinrepeat in this example. [Sequence in repeat being (1, 2, or 3 etc.)]. That way when its exported I could look up an ID and see the info attached with it. >> >> When I export the data, however, I do not see unique ID's for the repeat, and instead for the whole form. >> >> Thanks, >> Arram > > > > > > Hi Yaw, > > Thank you. > > I was able to use position(..) to assign each repeat a number. I then used concat to generate a full ID for each repeat that is like > > today_placeofdelivery_position(..) > 05292017-PlaceX-3 > > However, I would like the position number to have 4 digits, with leading zeros. so it would look like: > > 05292017-PlaceX-0003 > > > I tried using regex() but it wouldn't work for autogenerate numbers like the position. any other ideas? > > THanks, > Arram > > -- > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en > > --- > You received this message because you are subscribed to the Google Groups "ODK Community" group. > To unsubscribe from this group and stop receiving emails from it, send an email to opendatakit+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/d/optout.
3 Likes

Souirji,

You wouldn't use the UUID to retrieve a specific value.
indexed-repeat() and position() is still the best way to do that.
https://groups.google.com/d/msg/opendatakit/M_pERTptaA4/ltWOFzpWCQAJ
has a good example of how you can use it.

For constraints across repeats, I've attached a sample form that does
that for dates that might help. For the date constraint, you can use
indexed-repeat and position to capture the date of the previous
repeat. Then use relevancy to show a note when the date is out of
bounds. If that note is made required, it won't let the user proceed.
You should also only show this note when the number of repeats is
greater than 1 because the first date has nothing to compare against.

Yaw

repeat_constraint.xlsx (10.9 KB)

··· On Sat, May 27, 2017 at 2:06 PM, Souirji Abdelghani wrote: > Hi Yaw, > > How would you use this uuid to retrieve a specific variable's value in one > specific repeat? > > I want to apply this to put a constraint that each new value (i.e. in each > new repeat) of a variable must be smaller that the previous value (i.e. in > previous repeat) of the same field. > > Best regards > > > > > On Thursday, 25 May 2017 16:34:36 UTC+2, Yaw Anokwa wrote: >> >> Hi Arram, >> >> If you want to get the position of a repeat, use 'position(..)' >> >> If you want to generate a truly unique ID or a repeat, use 'once(uuid())' >> >> For both options, store the value inside a calculate field and put the >> methods (e.g., position(..)) in the calculation column. >> >> Try that and let us know how it goes, >> >> Yaw >> >> On Mon, May 22, 2017 at 5:35 AM, wrote: >> > Hi, >> > >> > I am new to odk so bare with me if this is incredibly simple. >> > >> > I am trying to assign a unique ID to each repeat based on parent >> > information and the sequence of repeat. >> > >> > To explain, attached is a simple example of repeats from XLSform. I >> > messed with the settings part to try to assign a unique ID to each repeat by >> > using instance_name but it simply assigns a unique ID to the overall parent >> > form. If that makes sense. >> > >> > I want each repeat to have a unique ID associated with it's data that >> > would essentially be today_placeofdelivery_sequenceinrepeat in this example. >> > [Sequence in repeat being (1, 2, or 3 etc.)]. That way when its exported I >> > could look up an ID and see the info attached with it. >> > >> > When I export the data, however, I do not see unique ID's for the >> > repeat, and instead for the whole form. >> > >> > Thanks, >> > Arram >> > >> > -- >> > -- >> > Post: opend...@googlegroups.com >> > Unsubscribe: opendatakit...@googlegroups.com >> > Options: http://groups.google.com/group/opendatakit?hl=en >> > >> > --- >> > You received this message because you are subscribed to the Google >> > Groups "ODK Community" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> > an email to opendatakit...@googlegroups.com. >> > For more options, visit https://groups.google.com/d/optout. > > -- > -- > Post: opendatakit@googlegroups.com > Unsubscribe: opendatakit+unsubscribe@googlegroups.com > Options: http://groups.google.com/group/opendatakit?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "ODK Community" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to opendatakit+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/d/optout.

Hi Yaw,

Thanks so much.

Best regards

··· On Sunday, 28 May 2017 22:04:55 UTC+2, Yaw Anokwa wrote: > > Souirji, > > You wouldn't use the UUID to retrieve a specific value. > indexed-repeat() and position() is still the best way to do that. > https://groups.google.com/d/msg/opendatakit/M_pERTptaA4/ltWOFzpWCQAJ > has a good example of how you can use it. > > For constraints across repeats, I've attached a sample form that does > that for dates that might help. For the date constraint, you can use > indexed-repeat and position to capture the date of the previous > repeat. Then use relevancy to show a note when the date is out of > bounds. If that note is made required, it won't let the user proceed. > You should also only show this note when the number of repeats is > greater than 1 because the first date has nothing to compare against. > > Yaw > > On Sat, May 27, 2017 at 2:06 PM, Souirji Abdelghani <ghani...@gmail.com > wrote: > > Hi Yaw, > > > > How would you use this uuid to retrieve a specific variable's value in > one > > specific repeat? > > > > I want to apply this to put a constraint that each new value (i.e. in > each > > new repeat) of a variable must be smaller that the previous value (i.e. > in > > previous repeat) of the same field. > > > > Best regards > > > > > > > > > > On Thursday, 25 May 2017 16:34:36 UTC+2, Yaw Anokwa wrote: > >> > >> Hi Arram, > >> > >> If you want to get the position of a repeat, use 'position(..)' > >> > >> If you want to generate a truly unique ID or a repeat, use > 'once(uuid())' > >> > >> For both options, store the value inside a calculate field and put the > >> methods (e.g., position(..)) in the calculation column. > >> > >> Try that and let us know how it goes, > >> > >> Yaw > >> > >> On Mon, May 22, 2017 at 5:35 AM, wrote: > >> > Hi, > >> > > >> > I am new to odk so bare with me if this is incredibly simple. > >> > > >> > I am trying to assign a unique ID to each repeat based on parent > >> > information and the sequence of repeat. > >> > > >> > To explain, attached is a simple example of repeats from XLSform. I > >> > messed with the settings part to try to assign a unique ID to each > repeat by > >> > using instance_name but it simply assigns a unique ID to the overall > parent > >> > form. If that makes sense. > >> > > >> > I want each repeat to have a unique ID associated with it's data that > >> > would essentially be today_placeofdelivery_sequenceinrepeat in this > example. > >> > [Sequence in repeat being (1, 2, or 3 etc.)]. That way when its > exported I > >> > could look up an ID and see the info attached with it. > >> > > >> > When I export the data, however, I do not see unique ID's for the > >> > repeat, and instead for the whole form. > >> > > >> > Thanks, > >> > Arram > >> > > >> > -- > >> > -- > >> > Post: opend...@googlegroups.com > >> > Unsubscribe: opendatakit...@googlegroups.com > >> > Options: http://groups.google.com/group/opendatakit?hl=en > >> > > >> > --- > >> > You received this message because you are subscribed to the Google > >> > Groups "ODK Community" group. > >> > To unsubscribe from this group and stop receiving emails from it, > send > >> > an email to opendatakit...@googlegroups.com. > >> > For more options, visit https://groups.google.com/d/optout. > > > > -- > > -- > > Post: opend...@googlegroups.com > > Unsubscribe: opendatakit...@googlegroups.com > > Options: http://groups.google.com/group/opendatakit?hl=en > > > > --- > > You received this message because you are subscribed to the Google > Groups > > "ODK Community" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to opendatakit...@googlegroups.com . > > For more options, visit https://groups.google.com/d/optout. >

A post was split to a new topic: How to learn advance programming with ODK?