Selected-at() and substr() not functioning

Hi Luke,
You might be able to avoid the errors by wrapping your formulas in ifs like
so:
if(count-selected( /test-form/Q1 ) > 0, selected-at( /test-form/Q1, 0), "")
Regards,
-Nathan

··· On Saturday, May 25, 2013 11:58:36 AM UTC-7, Luke MacDonald wrote: > > I have a multiselect question (Q1) with 17 choices and would like to > return the first selected value of that question in a calculate type (Q2). > > This should be possible using either selected-at() or substr(). However, > I both cause ODK validate to fail using xlsform and ODK collect to crash if > plugged into XML directly. > > I tried these three approaches: > > 1) nodeset="/test-form/Q2" type="string"/> > 2) type="string"/> > 3) type="string"/> > > > #1 causes ODK validate to fail with this error: > java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 > > #2 causes ODK validate to fail with this error > java.lang.StringIndexOutOfBoundsException: String index out of range: 2 > > #3 returns the entire string, i.e. all answers selected in Q1 (as > expected). Changing the starting position from 0 to 1, 2, 3, etc. also > works as expected. > > I'm totally confused, because I think I am applying selected-at() and > substr() in the straightforward shown on > http://opendatakit.org/help/form-design/binding/ > > It seems that ODK validate is looking for Q1 to already exist (i.e. > already be answered) in the case of #1 and #2, but doesn't care if Q1 > exists yet in the case of #3. Adding a relevancy statement doesn't help: > relevant =" /test-form/Q1 != '' " > >

Thanks, Nathan, that seems to be working!
Luke

··· On Sunday, May 26, 2013 6:49:29 PM UTC-4, Nathan wrote: > > Hi Luke, > You might be able to avoid the errors by wrapping your formulas in ifs > like so: > if(count-selected( /test-form/Q1 ) > 0, selected-at( /test-form/Q1, 0), "") > Regards, > -Nathan > > On Saturday, May 25, 2013 11:58:36 AM UTC-7, Luke MacDonald wrote: >> >> I have a multiselect question (Q1) with 17 choices and would like to >> return the first selected value of that question in a calculate type (Q2). >> >> This should be possible using either selected-at() or substr(). However, >> I both cause ODK validate to fail using xlsform and ODK collect to crash if >> plugged into XML directly. >> >> I tried these three approaches: >> >> 1) > nodeset="/test-form/Q2" type="string"/> >> 2) > type="string"/> >> 3) > type="string"/> >> >> >> #1 causes ODK validate to fail with this error: >> java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 >> >> #2 causes ODK validate to fail with this error >> java.lang.StringIndexOutOfBoundsException: String index out of range: 2 >> >> #3 returns the entire string, i.e. all answers selected in Q1 (as >> expected). Changing the starting position from 0 to 1, 2, 3, etc. also >> works as expected. >> >> I'm totally confused, because I think I am applying selected-at() and >> substr() in the straightforward shown on >> http://opendatakit.org/help/form-design/binding/ >> >> It seems that ODK validate is looking for Q1 to already exist (i.e. >> already be answered) in the case of #1 and #2, but doesn't care if Q1 >> exists yet in the case of #3. Adding a relevancy statement doesn't help: >> relevant =" /test-form/Q1 != '' " >> >>

FYI, the substr() issue has been filed, with a proposed fix, at
https://code.google.com/p/opendatakit/issues/detail?id=832. We might need a
similar fix for selected-at(). These functions really ought to be usable
without complex surrounding if's.

Chris

··· On Mon, May 27, 2013 at 12:49 AM, Nathan wrote:

Hi Luke,
You might be able to avoid the errors by wrapping your formulas in ifs
like so:
if(count-selected( /test-form/Q1 ) > 0, selected-at( /test-form/Q1, 0), "")
Regards,
-Nathan

On Saturday, May 25, 2013 11:58:36 AM UTC-7, Luke MacDonald wrote:

I have a multiselect question (Q1) with 17 choices and would like to
return the first selected value of that question in a calculate type (Q2).

This should be possible using either selected-at() or substr(). However,
I both cause ODK validate to fail using xlsform and ODK collect to crash if
plugged into XML directly.

I tried these three approaches:

#1 causes ODK validate to fail with this error: java.lang.**
ArrayIndexOutOfBoundsException**: 0 >= 0

#2 causes ODK validate to fail with this error java.lang.**
StringIndexOutOfBoundsExceptio**n: String index out of range: 2

#3 returns the entire string, i.e. all answers selected in Q1 (as
expected). Changing the starting position from 0 to 1, 2, 3, etc. also
works as expected.

I'm totally confused, because I think I am applying selected-at() and
substr() in the straightforward shown on http://opendatakit.org/help/**
form-design/binding/ http://opendatakit.org/help/form-design/binding/

It seems that ODK validate is looking for Q1 to already exist (i.e.
already be answered) in the case of #1 and #2, but doesn't care if Q1
exists yet in the case of #3. Adding a relevancy statement doesn't help:
relevant =" /test-form/Q1 != '' "

--
--
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/groups/opt_out.

Hello , is there a way of doing the same that Luke wants with .xcl 2 .xml
syntax?

any hint?

Thanks

··· 2013/5/29 Christopher Robert

FYI, the substr() issue has been filed, with a proposed fix, at
https://code.google.com/p/opendatakit/issues/detail?id=832. We might need
a similar fix for selected-at(). These functions really ought to be usable
without complex surrounding if's.

Chris

On Mon, May 27, 2013 at 12:49 AM, Nathan nabreit@gmail.com wrote:

Hi Luke,
You might be able to avoid the errors by wrapping your formulas in ifs
like so:
if(count-selected( /test-form/Q1 ) > 0, selected-at( /test-form/Q1, 0),
"")
Regards,
-Nathan

On Saturday, May 25, 2013 11:58:36 AM UTC-7, Luke MacDonald wrote:

I have a multiselect question (Q1) with 17 choices and would like to
return the first selected value of that question in a calculate type (Q2).

This should be possible using either selected-at() or substr().
However, I both cause ODK validate to fail using xlsform and ODK collect
to crash if plugged into XML directly.

I tried these three approaches:

#1 causes ODK validate to fail with this error: java.lang.**
ArrayIndexOutOfBoundsException**: 0 >= 0

#2 causes ODK validate to fail with this error java.lang.**
StringIndexOutOfBoundsExceptio**n: String index out of range: 2

#3 returns the entire string, i.e. all answers selected in Q1 (as
expected). Changing the starting position from 0 to 1, 2, 3, etc. also
works as expected.

I'm totally confused, because I think I am applying selected-at() and
substr() in the straightforward shown on http://opendatakit.org/help/**
form-design/binding/ http://opendatakit.org/help/form-design/binding/

It seems that ODK validate is looking for Q1 to already exist (i.e.
already be answered) in the case of #1 and #2, but doesn't care if Q1
exists yet in the case of #3. Adding a relevancy statement doesn't help:
relevant =" /test-form/Q1 != '' "

--
--
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/groups/opt_out.

--

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/groups/opt_out.

--

Jorge Durand Zurdo
*joduzu@gmail.com

I'm not quite sure what you mean by .xcl 2 .xml syntax. If you mean XLSForm
syntax, the answer is yes, the same approach of wrapping formulas in "if"
functions works there too.
Regards,
-Nathan

··· On Wednesday, May 29, 2013 6:43:05 AM UTC-7, Jorge Durand Zurdo wrote: > > Hello , is there a way of doing the same that Luke wants with .xcl 2 .xml > syntax? > > any hint? > > Thanks > > > 2013/5/29 Christopher Robert <cro...@surveycto.com > > >> FYI, the substr() issue has been filed, with a proposed fix, at >> https://code.google.com/p/opendatakit/issues/detail?id=832. We might >> need a similar fix for selected-at(). These functions really ought to be >> usable without complex surrounding if's. >> >> Chris >> >> >> >> On Mon, May 27, 2013 at 12:49 AM, Nathan <nab...@gmail.com >wrote: >> >>> Hi Luke, >>> You might be able to avoid the errors by wrapping your formulas in ifs >>> like so: >>> if(count-selected( /test-form/Q1 ) > 0, selected-at( /test-form/Q1, 0), >>> "") >>> Regards, >>> -Nathan >>> >>> On Saturday, May 25, 2013 11:58:36 AM UTC-7, Luke MacDonald wrote: >>>> >>>> I have a multiselect question (Q1) with 17 choices and would like to >>>> return the first selected value of that question in a calculate type (Q2). >>>> >>>> This should be possible using either selected-at() or substr(). >>>> However, I both cause ODK validate to fail using xlsform and ODK collect >>>> to crash if plugged into XML directly. >>>> >>>> I tried these three approaches: >>>> >>>> 1) >>> nodeset="/test-form/Q2" type="string"/> >>>> 2) >>> nodeset="/test-form/Q2" type="string"/> >>>> 3) >>> type="string"/> >>>> >>>> >>>> #1 causes ODK validate to fail with this error: java.lang.** >>>> ArrayIndexOutOfBoundsException**: 0 >= 0 >>>> >>>> #2 causes ODK validate to fail with this error java.lang.** >>>> StringIndexOutOfBoundsExceptio**n: String index out of range: 2 >>>> >>>> #3 returns the entire string, i.e. all answers selected in Q1 (as >>>> expected). Changing the starting position from 0 to 1, 2, 3, etc. also >>>> works as expected. >>>> >>>> I'm totally confused, because I think I am applying selected-at() and >>>> substr() in the straightforward shown on http://opendatakit.org/help/** >>>> form-design/binding/ >>>> >>>> It seems that ODK validate is looking for Q1 to already exist (i.e. >>>> already be answered) in the case of #1 and #2, but doesn't care if Q1 >>>> exists yet in the case of #3. Adding a relevancy statement doesn't help: >>>> relevant =" /test-form/Q1 != '' " >>>> >>>> -- >>> -- >>> 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/groups/opt_out. >>> >>> >>> >> >> -- >> -- >> 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/groups/opt_out. >> >> >> > > > > -- > > Jorge Durand Zurdo > *joduzu@gmail.com > * *skype user: **joduzu* > >

Thanks Nathan , Yes that's what I meant, but I wonder under witch column
should I insert the "if(count-selected( /test-form/Q1 ) > 0, selected-at(
/test-form/Q1, 0), "")" relevant? calculation?

Best

Jorge

··· 2013/5/29 Nathan

I'm not quite sure what you mean by .xcl 2 .xml syntax. If you mean
XLSForm syntax, the answer is yes, the same approach of wrapping formulas
in "if" functions works there too.
Regards,
-Nathan

On Wednesday, May 29, 2013 6:43:05 AM UTC-7, Jorge Durand Zurdo wrote:

Hello , is there a way of doing the same that Luke wants with .xcl 2
.xml syntax?

any hint?

Thanks

2013/5/29 Christopher Robert cro...@surveycto.com

FYI, the substr() issue has been filed, with a proposed fix, at
https://code.google.com/p/**opendatakit/issues/detail?id=**832https://code.google.com/p/opendatakit/issues/detail?id=832.
We might need a similar fix for selected-at(). These functions really ought
to be usable without complex surrounding if's.

Chris

On Mon, May 27, 2013 at 12:49 AM, Nathan nab...@gmail.com wrote:

Hi Luke,
You might be able to avoid the errors by wrapping your formulas in ifs
like so:
if(count-selected( /test-form/**Q1 ) > 0, selected-at( /test-form/Q1,
0), "")
Regards,
-Nathan

On Saturday, May 25, 2013 11:58:36 AM UTC-7, Luke MacDonald wrote:

I have a multiselect question (Q1) with 17 choices and would like to
return the first selected value of that question in a calculate type (Q2).

This should be possible using either selected-at() or substr().
However, I both cause ODK validate to fail using xlsform and ODK collect
to crash if plugged into XML directly.

I tried these three approaches:

#1 causes ODK validate to fail with this error: java.lang.**
ArrayIndexOutOfBoundsException: 0 >= 0

#2 causes ODK validate to fail with this error java.lang.**
StringIndexOutOfBoundsException: String index out of range: 2

#3 returns the entire string, i.e. all answers selected in Q1 (as
expected). Changing the starting position from 0 to 1, 2, 3, etc. also
works as expected.

I'm totally confused, because I think I am applying selected-at() and
substr() in the straightforward shown on http://opendatakit.org/help/*
*fo**rm-design/binding/http://opendatakit.org/help/form-design/binding/

It seems that ODK validate is looking for Q1 to already exist (i.e.
already be answered) in the case of #1 and #2, but doesn't care if Q1
exists yet in the case of #3. Adding a relevancy statement doesn't help:
relevant =" /test-form/Q1 != '' "

--
--
Post: opend...@googlegroups.com
Unsubscribe: opendatakit...@**googlegroups.com

Options: http://groups.google.com/**group/opendatakit?hl=enhttp://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/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--

Post: opend...@googlegroups.com
Unsubscribe: opendatakit...@**googlegroups.com

Options: http://groups.google.com/**group/opendatakit?hl=enhttp://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/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--

Jorge Durand Zurdo
*joduzu@gmail.com
**skype user: *joduzu

--
--
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/groups/opt_out.

--

Jorge Durand Zurdo
*joduzu@gmail.com

sorry I got it !! :slight_smile:

··· 2013/5/29 Jorge Durand Zurdo

Thanks Nathan , Yes that's what I meant, but I wonder under witch column
should I insert the "if(count-selected( /test-form/Q1 ) > 0, selected-at(
/test-form/Q1, 0), "")" relevant? calculation?

Best

Jorge

2013/5/29 Nathan nabreit@gmail.com

I'm not quite sure what you mean by .xcl 2 .xml syntax. If you mean
XLSForm syntax, the answer is yes, the same approach of wrapping formulas
in "if" functions works there too.
Regards,
-Nathan

On Wednesday, May 29, 2013 6:43:05 AM UTC-7, Jorge Durand Zurdo wrote:

Hello , is there a way of doing the same that Luke wants with .xcl 2
.xml syntax?

any hint?

Thanks

2013/5/29 Christopher Robert cro...@surveycto.com

FYI, the substr() issue has been filed, with a proposed fix, at
https://code.google.com/p/**opendatakit/issues/detail?id=**832https://code.google.com/p/opendatakit/issues/detail?id=832.
We might need a similar fix for selected-at(). These functions really ought
to be usable without complex surrounding if's.

Chris

On Mon, May 27, 2013 at 12:49 AM, Nathan nab...@gmail.com wrote:

Hi Luke,
You might be able to avoid the errors by wrapping your formulas in ifs
like so:
if(count-selected( /test-form/**Q1 ) > 0, selected-at( /test-form/Q1,
0), "")
Regards,
-Nathan

On Saturday, May 25, 2013 11:58:36 AM UTC-7, Luke MacDonald wrote:

I have a multiselect question (Q1) with 17 choices and would like to
return the first selected value of that question in a calculate type (Q2).

This should be possible using either selected-at() or substr().
However, I both cause ODK validate to fail using xlsform and ODK collect
to crash if plugged into XML directly.

I tried these three approaches:

#1 causes ODK validate to fail with this error: java.lang.**
ArrayIndexOutOfBoundsException: 0 >= 0

#2 causes ODK validate to fail with this error java.lang.**
StringIndexOutOfBoundsException: String index out of range: 2

#3 returns the entire string, i.e. all answers selected in Q1 (as
expected). Changing the starting position from 0 to 1, 2, 3, etc. also
works as expected.

I'm totally confused, because I think I am applying selected-at() and
substr() in the straightforward shown on http://opendatakit.org/help/
form-design/binding/http://opendatakit.org/help/form-design/binding/

It seems that ODK validate is looking for Q1 to already exist (i.e.
already be answered) in the case of #1 and #2, but doesn't care if Q1
exists yet in the case of #3. Adding a relevancy statement doesn't help:
relevant =" /test-form/Q1 != '' "

--
--
Post: opend...@googlegroups.com
Unsubscribe: opendatakit...@**googlegroups.com

Options: http://groups.google.com/**group/opendatakit?hl=enhttp://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/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--

Post: opend...@googlegroups.com
Unsubscribe: opendatakit...@**googlegroups.com

Options: http://groups.google.com/**group/opendatakit?hl=enhttp://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/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--

Jorge Durand Zurdo
*joduzu@gmail.com
**skype user: *joduzu

--
--
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/groups/opt_out.

--

Jorge Durand Zurdo
*joduzu@gmail.com

--

Jorge Durand Zurdo
*joduzu@gmail.com