Conditions + Multiple calculations

I'me trying to manage the "if" conditions with other calculation forms like the function below:

if(string-length(${q_11}>=4),concat(${q_9},'0',${q_11}),if(string-length(${q_11}<=3),concat(${q_9},'00',${q_11})))

I try to put "MABM"+2035 and "MABM"+203 and the result is the same: MABM02035 and MABM0203.
What I want to do is:

  • if the number of charaters (numbers) is >=4 the function concatenat the ${q_9},'0',${q_11} - (MABM02035)
  • if the number of charaters (numbers) is <=4 the function concatenat the ${q_9},'00',${q_11} - (MABM00203)

Any help plz...?! Thank you!

1 Like

Hi @Nuno_Passos,
I think I've been able to solve your problem!

First of all, string-length is a function that returns a string length, so instead of:
string-length(${q_11}>=4)
you actually want to write:
string-length(${q_11})>=4

The string functions are here: https://docs.getodk.org/form-operators-functions/#strings

I've attached a sample xlsform that you can copy and paste from!

example_string-length_concat.xlsx (19.4 KB)

Hope that helps!
Janna

3 Likes

Hi @janna,
Many thanks for your help! It worked well as you said to do!
Sometimes the errors are in small details.
Problem solved! :slight_smile:

1 Like

Fantastic :slight_smile: Glad to hear it! Have a great day!

3 Likes