Creating random number only once per form

I want to generate a random number only once per form creation. I am using this calculation:

once(int(random())*10)

But am getting this error:

Error loading form. Error: [“FormLogicError: Could not evaluate: once(int(100*random())+1), message: Failed to execute ‘evaluate’ on ‘Document’: The string ‘once(40)’ is not a valid XPath expression.”]

1 Like

Hi @iesmail

We currently don’t support once but the same can be achieved as follows:

Let’s say you have a calculate field called my_random.
Your calculation would be: if(${my_random}='',int(random())*10, ${my_random})

We’ll support this (and others) once we roll out a release with the latest openrosa-xpath-evaluator. Currently targeted for the 3.12 release.

3 Likes