Evaluation of IsAnswered when referencing another roster row

I am checking to make sure that if person A identifies person B as his/her spouse, then person B also identifies person A as his/her spouse. I used the example in the Standard Survey Modules - Household Roster - spouse_pid_1, verification #3 as an example of the logic. The code I tried is given below. memfamily is the name of the roster; name_spouse is a single-select question linked to the roster with the names of the household members.

memfamily[self[0]].IsAnswered(name_spouse) ?

memfamily[self[0]].name_spouse[0]==@rowcode : true

When I test the code, and answer the questions for the first person in the roster, the condition “memfamily[self[0]].IsAnswered(name_spouse)” is being evaluated as True even though I have not yet answered any question for any other household members, and the filter on the question excludes the current person’s name from being displayed. I even tried hard coding a specific row number “memfamily[1].IsAnswered(name_spouse)” (which should refer to the second person in the household) and it still evaluated as True even though questions for that person had not been answered. There is no problem using IsAnswered without referencing another row (i.e. I tried it just referring to a question for the current person and it evaluated correctly).

Any suggestions?

Hello Lecily!

Sorry to hear you ran into troubles. It is not apparent from your question what exactly is going on, but:

  1. Not R[c].IsAnswered(Q), but IsAnswered(R[c].Q)
    I am not sure why that code even compiles.

  2. Do not write Condition1 ? Condition2 : true
    Instead write !Condition1 || Condition2

Both are perfectly valid syntax and are completely equivalent, but I’ve seen so many people confused by the first version, that it’s just not worth it.

  1. I’ve added a demo section Spouses to the “Public example User questions and common patterns” which demonstrates how we can verify the mutual marriage declaration with
  • filtering;
  • hints;
  • errors.

If #1 doesn’t fix it and #3 is not suitable, we can go back to your original problem.

Thank you - #1 corrects the problem.

FYI - you should have someone update the example in the Standard Survey Modules - Household Roster - spouse_pid_1, verification #3 (and all the other spouse questions in that example), as they all show the syntax that I was using originally.