Calculation Field if statement

I have designed an ODK form where I am using a calculation field to auto-populate a field with values from values of another field. i.e. I have a specimen ID that is scanned but this field is not required. In the event it is not possible to scan the specimen ID the user can enter manually in the text field which is marked as required. If the barcode is scanned; the manual field entry is auto-populated with the scan value. Problem: If the barcode was no scanned and there is a manual entry of barcode value the field is validated as returns blank hence not possible to save the form. I am using the calculation field with the logic if(string-length(${id})>0,${id},"") .

I am using ODK aggregate.

I would like to attach the xlsForm here but I can't see the attach button.

Hi Samuel,

I would suggest you try:

  • The barcode field non-required.
  • The text field (e.g. manual_barcode that is required and relevant for
    string-length(${id})=0
  • A calculated field which uses the formula:
    if(string-length(${id})>0,${id},${manual_bardcode})
    (assuming ${id} is your scanned barcode)

I hope this helps!

Best,
Andrea

P.S.
To upload a file you can press the button with the upwards arrow (see icon below)
Screen Shot 2021-05-06 at 18.54.32

or you can simply drag-and-drop the file in the text box.