Constraints in ODK

Hi, I just want to figure out how do we use constraints in ODK. I have gone through the ODK logic guide and tried few options but the while uploading the form to aggregate it gives an error. What I want basically is that a response question 2 should be less than what was reported in question 1.

I have tried the following options in constraint option in ODK Build:
.<=${question_one}
(.)<=${question_one}
.<=question_one

Nothing seems to work. If any one can guide that would be great. Seems like a easy solution to it, but I cant figure it out. Thanks.

Hi @Abdullah_Khan

please try this sample form: constraint.xlsx (5.7 KB)

it works well to me.

Hi Grzesiek, Thankyou for replying. I have tried the same code as mentioned in the first option above in my post. However, when I enter it this way and upload the form on the aggregate i get the following error:

"Could not upload the form. Aggregate could not validate the form contents. Please make sure your form is valid and try again."

Once i remove the code, it gets uploaded.

Could you attach your form?

in my case its something like this.

constraint_Mine.xlsx (9.9 KB)

Everything looks fine... could you describe steps you follow?
In my case it's:

  1. Go to http://opendatakit.org/xlsform/ and convert the downloaded xls form and download xml version.
  2. Go to Form Management page on your aggregate server and upload the downloaded form.

If you do exactly the same what aggregate version do you use?

Im currently working on ODK Build (online). I just made the form on it and uploading form on aggregate directly from it. I might try manually uploading it as you suggest.

nope no luck.. get the following error if I do it manually.

Error: Problem with JavaRosa Parsing Form: org.opendatakit.aggregate.exception.ODKIncompleteSubmissionData: Javarosa failed to construct a FormDef. Is this an XForm definition?

Just to be clear: do you upload a converted xml form or maybe xls what's not allowed?

no not working in XLS. Just developing it on ODK Build. Tried saving it into XML from it and uploaded manually as you mentioned to try that aswell but got the error message as above.

Once i remove the constraint and upload from ODK Build it gets uploaded but when I enter it, it gives the form is not valid error.

If you add constraints using ODK Build you probably need to use:
.&lt;= /constraint_Mine/HH_MnthlyIncome
not
.<=${HH_MnthlyIncome}
that second version is used in xls.

Could you try?

Oh so if my first question has the following attributes:
Data name: HH_MnthlyIncome
Label: Households monthly income
Kind: Integer

and my second question has the following:
Data name: HH_MnthlyAgriIncome
Label: Households monthly agriculture income
Kind: Integer

what constraint should I put in the second question exactly?
not .<=${HH_MnthlyIncome}??

If it's via ODK Build please try exactly:

but why are we referring to 'constraint_Mine file' in the code? that was just an example i made to copy your xls file.

It looks like this>

Using constraints via ODK Build is hard. I would recommend using xls and then you could use the expression you want -

if you use ODK Build you can't use such a convenient way and you need to use a path to your question.
so in my sample

constraint_Mine - form name
HH_MnthlyIncome - question name

but if you have an additional group (like it's in the attached image) you need to add that group name too eg.
.&amp;lt;= /constraint_Mine/additional_group/HH_MnthlyIncome

That's because if you use xls and for example expression like:
.<=${HH_MnthlyIncome}
after converting to xml it looks like the second version:
.&lt;= /constraint_Mine/HH_MnthlyIncome
it's converted but ODK Build doesn't convert that so you need to use the second version manually.

Oh!! ok I will try this and reply if it worked or not. Thanks for your time Grzesiek, much appreciated.

No problem, let us know in case of any problems.

Hi Grzegorz, I tried that code you shared yesterday but no luck. I also exported my ODK form into XLS Form from the ODK Build, and entered the basic code '.<=${HH_MnthlyIncome}' in the XLS file. Then I tried to convert it into X Form from the weblink you shared 'http://opendatakit.org/xlsform/'. However when I converted it I got the following error on that too:

Error: b'ODK Validate Errors:\n>> XForm is invalid. See above for the errors.\norg.javarosa.xform.parse.XFormParseException: Encountered a problem with display condition for node [${Age}] at line: (), Bad node: org.javarosa.xpath.parser.ast.ASTNodeAbstractExpr@64cee07\n\nResult: Invalid'