Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Ending, suspending, and rolling back interviews > Dealing with off-path data
 
Dealing with off-path data
Off-path data consists of responses to questions that are no longer on the interview path. They occur when a respondent backtracks and changes an answer to a question, and that change causes different questions to be asked. The questions that were asked the first time but that are now no longer relevant are called off-path questions.
Off-path data exists in two places: in the case data and in the value cache. Off path case data is set to null when the interview completes. Off-path data in the value cache is cleared whenever a respondent navigates backwards in an interview, except in projects where you have chosen to keep all off-path data. In this case only, the off-path data remains in the case data and in the value cache. You can change these settings so that, for example, all off-path case data is nulled and all off-path value cache data is deleted as soon as a question becomes off-path.
Case data
To specify what to do with off-path case data, type:
IOM.OffPathDataMode = OffPathDataModes.mode
near the start of the routing section of the script, where mode is one of the following:
dmClearOnComplete to set the case data for all off-path questions to null when the interview completes. Off-path data is kept for stopped or timed out interviews. This is the default.
dmClearOnExit to set the case data for off-path questions to null when the interview ends for any reason (that is, completes, stops, or times out). Normally, responses are written straight to the case data database. With this option, off-path responses are left in the case data until the interview ends. At this point, the interviewing program nulls all responses in the case data that are not on-path at the point the interview ended.
dmClearOnNavigateBack to set the case data for off-path questions to null as soon as the respondent clicks the Previous button or skips to another question using Goto or First, or when an ISavePoint.Go() instruction is encountered in the routing section of the interview script. With this option, the case data always reflects the questions that are on the current interview path, so this option does not attempt to null off-path data on exit because it assumes that the case data is up to date. If an interview is restarted from sample management, and a different path through the interview is taken, any questions not re-asked after the restart are not set to null.
dmKeep to keep all off-path data.
When referencing an off-path question via script, the question returns a null or empty value, even if you keep off path data. Use Info.OffPathResponse to obtain a question’s off-path response. You can also use Qname.Response.Value = Qname.Info.OffPathResponse to force a question back on-path.
The following example sets the case data for all off-path questions to null as soon as the respondent goes back to an earlier question. The metadata for the example is:
Film "Which film did you like best?" categorical [1..1]
{
FilmA "The first one",
FilmB "The second one"
};
FilmAQ1 "The first film starred Ben Brown. What others
of his films have you seen?" categorical [1..]
{
FilmBB1, FilmBB2, FilmBB3,
NoBB "No others" na
};
FilmAQ2 "What did you like best about the first film?"
text;
FilmBQ1 "This film starred Emma Filby. What others of her
films have you seen?" categorical [1..]
{
FilmEF1, FilmEF2, FilmEF3,
NoEF "No others" na
};
FilmBQ2 "What did you like best about the second film?"
text;
LastQ "Which film do you think will be the most successful
at the box office?" categorical [1..1]
{
FilmA1 "The first one",
FilmB2 "The second one"
};
The routing section contains the following statements:
IOM.OffPathDataMode = OffPathDataModes.dmClearOnNavigateBack
Film.Ask()
If Film = {FilmA} Then
FilmAQ1.Ask()
FilmAQ2.Ask()
Else
FilmBQ1.Ask()
FilmBQ2.Ask()
End If
LastQ.Ask()
FilmSummary.Show()
The respondent starts by saying that they preferred the first film and answers FilmAQ1 and FilmAQ2. At LastQ the respondent starts clicking Previous to backtrack to Film. Each time the respondent clicks Previous, the case data for the question they has just left is set to null. On reaching Film, the respondent changes the answer to show that they preferred the second film and then answers FilmBQ1, FilmBQ2, and LastQ. The case data for the new questions is written and reflects the respondent’s final path through the script.
However, when the FilmSummary question is displayed, it shows the answers to all the questions that the respondent answered, whether or not they are on the interview path. This is because the interviewing program reads the answers to the questions on this page from the value cache rather than from the case data. The case data is correct, but it could be confusing for the respondent to see the answers to the off-path questions displayed. If you delete the data from the value cache, as shown in Value cache data, this does not happen.
If you choose generally not to retain off-path data, you can still keep off-path data for certain questions by manually setting the responses to those questions to be on-path. Type:
Qname.Response.Value = Qname.Info.OffPathResponse
where Qname is the name of the question whose off-path data you want to keep.
Value cache data
You can remove off-path data from the value cache for single questions or for all off-path questions. To clear the answer to a specific question, place the following statement in the routing section of the script:
IOM.Questions["Qname"].ClearOffPathResponse()
To clear the answers to all off-path questions, use:
IOM.Questions[..].ClearOffPathResponse()
An easy way of deleting all off-path data from the value cache is to use interview scripting events to check whether the current response to the question is the same as the previous response (if any) and to discard all off-path data from the value cache if they are not. To illustrate how this works, we'll use the same metadata as before but with the following routing:
IOM.OffPathDataMode = OffPathDataModes.dmClearOnNavigateBack
Film.Ask()
If Film = {FilmA} Then
FilmAQ1.Ask()
FilmAQ2.Ask()
Else
FilmBQ1.Ask()
FilmBQ2.Ask()
End If
LastQ.Ask()
FilmSummary.Show()
' This event runs before a question is asked.
Sub OnBeforeQuestionAsk(Question, IOM)
Dim Prop
Set Prop = IOM.Properties.FindItem("PrevResponse")
If (IsNullObject(Prop)) Then
Set Prop = IOM.Properties.CreateProperty()
Prop.Name = "PrevResponse"
Prop.Value = Null
IOM.Properties.Add(Prop)
End If
If (Question.QuestionDataType <> DataTypeConstants.mtNone) Then
Prop.Value = Question.Info.OffPathResponse
End If
End Sub

' This event runs after a question has been asked.
Sub OnAfterQuestionAsk(Question, IOM)
If (Question.QuestionName = "Film") Then
If (IOM.Properties["PrevResponse"] <> Question.Response.Value) Then
IOM.Questions[..].ClearOffPathResponse()
End If
End If
End Sub
This routing uses the OnBeforeQuestionAsk event and OnAfterQuestionAsk event to define actions that are to take place immediately before and after every question is asked.
In this script, OnBeforeQuestionAsk checks whether the current question has a PrevResponse property. If it does not, the script creates one and sets it to null, otherwise it assigns the question’s current response (if it has one) to the property. All this is in preparation for work that will be carried out after the question has been asked.
OnAfterQuestionAsk checks whether the respondent has just answered the Film question. If so, it compares the question’s previous response with its current response and, if they are not the same, deletes the data from any questions that have now become off-path from the value cache.
Let’s follow our previous respondent through this routing script. When Film is displayed, OnBeforeQuestionAsk creates a PrevResponse property for it and sets its value to null. The respondent chooses “The first film” and clicks Next. The OnAfterQuestionAsk event compares this answer with the null value in PrevResponse but does nothing else because the two do not match. A similar thing happens for FilmAQ1 and FilmAQ2.
At LastQ, the respondent clicks Previous. Because this routing script uses the default behavior for clearing data from the case data file, the case data is not nulled as the respondent backtracks (this does not happen until the end of the interview). However, what happens to the value cache is different. When the respondent moves from LastQ to FilmAQ2, OnBeforeQuestionAsk runs before FilmAQ2 is displayed and sets its PrevResponse property to the current answer to that question. A similar thing happens for the other questions as the respondent backtracks to Film.
At the point at which Film is redisplayed, its PrevResponse value is “The first one”. The respondent chooses “The second one” and OnAfterQuestionAsk runs. The current question is Film, so the interviewing program compares the current response with the previous one. They are not the same so the data held in the value cache for all related questions is deleted.
The respondents then answers FilmBQ1, FilmBQ2, and LastQ. When the Summary page is displayed, only Film, FilmBQ1 and FilmBQ2 will have answers because these are the only values present in the value cache. At this point, the case data still contains data for all the questions that the respondent answered. Data for off-path questions is set to null when the respondents clicks Next and the interview ends.
See also
Ending, suspending, and rolling back interviews