2.0 calculate/assign usage

Good day,

I'm obviously missing something in how assign/calculation should be used in
the 2.0 tools:

I initially thought something like this would work:
type name display.text calculation

··· --------------------------------------------------------------- text myname Enter your name assign surname data('myname') note note1 surname: {{data.surname}}

This throws an error (in the developer Javascript console) complaining
about an unknown type.
I'm guessing it doesn't know what type "surname" should be.

I changed it to:
type name display.text calculation

text myname Enter your name
text surname
assign surname data('myname')
note note1 surname: {{data.surname}}
The error doesn't occur (as it knows surname is of type "text").
But now it displays a blank prompt for "text surname" (as expected)

I then tried removing the "assign":
type name display.text calculation

text myname Enter your name
text surname data('myname')
note note1 surname: {{data.surname}}

But it still displays a blank prompt, and doesn't assign myname to surname.

What is the correct way to work with assign and calculations?

Thanks,
Andrew

If you would like to store information in a survey without displaying a
prompt, you can use the model worksheet and then use assign to give it a
value. I have attached an example to illustrate how to accomplish this.

Clarice

assignExampleForm.xlsx (35.4 KB)

··· On Mon, May 30, 2016 at 8:42 AM, Andrew wrote:

Good day,

I'm obviously missing something in how assign/calculation should be used
in the 2.0 tools:

I initially thought something like this would work:
type name display.text calculation

text myname Enter your name
assign surname data('myname')
note note1 surname: {{data.surname}}

This throws an error (in the developer Javascript console) complaining
about an unknown type.
I'm guessing it doesn't know what type "surname" should be.

I changed it to:
type name display.text calculation

text myname Enter your name
text surname
assign surname data('myname')
note note1 surname: {{data.surname}}
The error doesn't occur (as it knows surname is of type "text").
But now it displays a blank prompt for "text surname" (as expected)

I then tried removing the "assign":
type name display.text calculation

text myname Enter your name
text surname data('myname')
note note1 surname: {{data.surname}}

But it still displays a blank prompt, and doesn't assign myname to surname.

What is the correct way to work with assign and calculations?

Thanks,
Andrew

--

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.

Perfect, that works, thanks.

Regards,
Andrew

··· On Tuesday, 31 May 2016 23:05:29 UTC+2, clarice larson wrote: > > If you would like to store information in a survey without displaying a > prompt, you can use the model worksheet and then use assign to give it a > value. I have attached an example to illustrate how to accomplish this. > > > Clarice > > On Mon, May 30, 2016 at 8:42 AM, Andrew <acawo...@gmail.com > wrote: > >> Good day, >> >> I'm obviously missing something in how assign/calculation should be used >> in the 2.0 tools: >> >> I initially thought something like this would work: >> type name display.text calculation >> --------------------------------------------------------------- >> text myname Enter your name >> assign surname data('myname') >> note note1 surname: {{data.surname}} >> >> This throws an error (in the developer Javascript console) complaining >> about an unknown type. >> I'm guessing it doesn't know what type "surname" should be. >> >> >> I changed it to: >> type name display.text calculation >> --------------------------------------------------------------- >> text myname Enter your name >> text surname >> assign surname data('myname') >> note note1 surname: {{data.surname}} >> The error doesn't occur (as it knows surname is of type "text"). >> But now it displays a blank prompt for "text surname" (as expected) >> >> >> I then tried removing the "assign": >> type name display.text calculation >> --------------------------------------------------------------- >> text myname Enter your name >> text surname data('myname') >> note note1 surname: {{data.surname}} >> >> But it still displays a blank prompt, and doesn't assign myname to >> surname. >> >> >> What is the correct way to work with assign and calculations? >> >> Thanks, >> Andrew >> >> -- >> -- >> 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. >> > >

Thanks.
Please, I have five area in ha. I would like compute the total with calculation fonction.
If I choose all of five area, the calculation fonction is ok. But if I choose less than five (eg. 3 area), th e calculation fonction don't compute.
Please to help me.
Moïse

I think there are two options:

  1. Always fill in all five areas, but put zero if choosing only some. Or assign as zero from the start and only fill in with values if non-zero. Then your existing calculation should work.
  2. Use a different formula (I am not sure how you are doing the calculation exactly, but a different operator might work fine with missings).

Thank you for your response

Another problem.
I have figer in different group. Sould I compute the big total with calculation function. If yes, how does this works?
Thanks

I am not quite sure what you mean about the different groups. In general, calculations in ODK-X can take any JavaScript operators. You can refer to variables/prompts, for example,
( data('q8101_2') -data('q303_3') )

Thank you for your response.
Another problem.
I have 5 quantitative variable in 5 diferent group.
I compute the total with calculation function.
On the plaform, the calculation compute the result. But on my phone, it's no works.
Why?
Thanks again.

Hi @msodjinou!
Can you share your form and tell us more about what phone version you are using, what version of the ODK-X tools, etc.? This will help us figure out why you might end up with different results on the computer versus phone.