String calculation in ODK Survey

Hi everyone,

I'm using ODK Survey, I use substr(data('mydata'), 4) to extract substring from onother following:
https://opendatakit.org/help/form-design/binding/

calculation type value_list name display.text
select_one field1_csv field1 select one
substr(data('field1'), 4 assign field2
note substring is {{data.field2}}

But it doesn't work.
Anyone can help me or point me where I can find Calculation tutorial of ODK Survey.

Thanks in advance.

You are mixing ODK 1.x and ODK 2.0 features.

In ODK 2.0, formulas are written using Javascript -- you are no longer
restricted to the functions that we define for you.

We provide the data('fieldname') function to access the value for that
field. After that, you're free to use any Javascript function.

So you would write:

data('field1').substr(4)

This would give an error if 'field1' is not required (i.e., is null or
undefined). So you might need to test for that condition first.

(The link you gave to the form binding help page is for the ODK 1.x tools.)

··· On Mon, Jul 6, 2015 at 10:43 PM, wrote:

Hi everyone,

I'm using ODK Survey, I use substr(data('mydata'), 4) to extract substring
from onother following:
https://opendatakit.org/help/form-design/binding/

calculation type value_list name
display.text
select_one field1_csv field1 select one
substr(data('field1'), 4 assign field2
note substring
is {{data.field2}}

But it doesn't work.
Anyone can help me or point me where I can find Calculation tutorial of
ODK Survey.

Thanks in advance.

--

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.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

1 Like

Hi Sundt,

Thank you for your help. It worked.

Vào 00:19:50 UTC+7 Thứ Tư, ngày 08 tháng 7 năm 2015, Sundt Sundt đã viết:

··· > > You are mixing ODK 1.x and ODK 2.0 features. > > In ODK 2.0, formulas are written using Javascript -- you are no longer > restricted to the functions that we define for you. > http://www.w3schools.com/js/js_string_methods.asp > > We provide the data('fieldname') function to access the value for that > field. After that, you're free to use any Javascript function. > > So you would write: > > data('field1').substr(4) > > This would give an error if 'field1' is not required (i.e., is null or > undefined). So you might need to test for that condition first. > > (The link you gave to the form binding help page is for the ODK 1.x tools.) > > > On Mon, Jul 6, 2015 at 10:43 PM, <thanhh...@gmail.com > wrote: > >> Hi everyone, >> >> I'm using ODK Survey, I use substr(data('mydata'), 4) to extract >> substring from onother following: >> https://opendatakit.org/help/form-design/binding/ >> >> calculation type value_list name >> display.text >> select_one field1_csv field1 select one >> substr(data('field1'), 4 assign field2 >> note substring >> is {{data.field2}} >> >> But it doesn't work. >> Anyone can help me or point me where I can find Calculation tutorial of >> ODK Survey. >> >> Thanks in advance. >> >> -- >> -- >> 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. >> > > > > -- > Mitch Sundt > Software Engineer > University of Washington > mitche...@gmail.com >