Is it possible to use the if-statement to to manipulate the value of a variable?

Hello there, we are working with Farmers, some of whom do already have a unique Grower Number (GN). We are using pulldata() to get the names of those with a GN number. For those who don’t, we have to enter the names manually. So, we have pulldata(‘GN5’,’FN’,’ID’,${GN}) and that works fine. The name for the pulldata variable is FN
The Farmers name with a GN is displayed as a label for the text field Fname.
If there is no GN the user can type in the name which is stored in the variable ${Fname}

What I am trying to do is something like this: if((${GN} !=’’),${Fname} = ${FN},${Fname}))
If there is a GN, then use the data from pulldata (FN) else use the typed in data (Fname).
Unfortuantely this is not working. Any suggestions are welcome.
Thanks
Thomas

That is not the issue. I learned the hard way that the csv is static. My problem is the if statement if(($(gn) =’’), ${fn} =${fname}, ${fn})). The question is if I can manipulate variables with the if clause. Thanks

1 Like

Dear Tafataona,

Yes you can create a new variable through the if function in a question of the calculate type (and then show it as a label in a text question). However in your example your second argument is a logical test evaluating to true or false. Also your brackets seem not right. Can you try something like this

if(${GN} !=’’, ${FN}, ${Fname})

this reads like if ${GN} is empty, take variable ${FN} else take the value of variable ${Fname}

I hope this helps,

Jozef

1 Like

Hello @bd_burundi,
Maybe something is wrong here?

The if says != , so that would read NOT empty
Best regards

2 Likes

Hello wroos and tafataona,

Indeed I overlooked the !. So

if(${GN} !=’’, ${FN}, ${Fname})

reads if ${GN} is not empty, take variable ${FN} else take the value of variable ${Fname}

Jozef

2 Likes

Morning Jozef,
works like a charm! Thanks a lot and Greetings from Zimbabwe.

1 Like