Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Events > Using events to save interview paradata > Paradata example script
 
Paradata example script
The DDL comes with an example script that illustrates how you can gather paradata using events. You'll find the script and its associated files in the DDL \Scripts\Interview\Frequently Asked Questions\Events folder wherever you have installed the DDL. Follow the instructions in the ReadMe file to set up and run the script.
The notes in this section explain how the events are used to gather and update the paradata during the course of the interview. Refer to the function definitions and comments in the EnglishMuseum_WithParadata.mdd example file for information about the functions themselves. The events are defined as follows:
Sub OnInterviewStart(IOM)
AddInterviewParadata(IOM)
End Sub

Sub OnInterviewEnd(IOM)
UpdateInterviewParadata(IOM)
End Sub

Sub OnBeforeQuestionAsk(Question, IOM)
PrepareQuestionParadata(Question, IOM)
End Sub

Sub OnBeforeQuestionValidation(Question,IOM)
If IOM.Navigations.LastSelected <> NavigationTypes.nvNext And _
IOM.Navigations.LastSelected <> NavigationTypes.nvLast Then
AddQuestionParadata(Question, IOM)
End If
End Sub

Sub OnAfterQuestionAsk(Question, IOM)
AddQuestionParadata(Question, IOM)
IOM.Info.EstimatedProgress = IOM.Info.EstimatedProgress + 1
End Sub
These definitions cause specific things to happen at the following points in an interview.
OnInterviewStart runs at the start of each interview and calls the AddInterviewParadata function. This function:
Creates a connection to the paradata database and adds the connection to the global objects for the interview.
Creates a new interview property called QuestionStartTime and adds it to the properties list for the current interview.
Runs the UpdateInterviewParadata function to check whether a paradata record already exists for this interview (that is, whether this is a restarted interview). If a record exists, that record is updated; if not, a new record is created.
OnBeforeQuestionAsk runs before each question is asked and calls the PrepareQuestionParadata function, which sets the value of the QuestionStartTime property to the current time. This gives you the time at which each question was displayed. This is later used in the OnAfterQuestionAsk() event to determine the ElapsedTime for the question.
OnBeforeQuestionValidation runs as soon as the respondent clicks a navigation button (before validation and the OnAfterQuestionAsk event) and, if the respondent clicked any navigation button other than Next or Last, calls the AddQuestionParadata function. This records paradata for questions that were displayed but were not immediately answered because the respondent skipped to a different question (for example, used Previous to go back to the previous question). This ensures that you have a complete record of every time a question was displayed rather than just every time a question was answered. The event does nothing if the respondent clicks Next or Last because these respondents pass through the OnAfterQuestionAsk event.
OnAfterQuestionAsk runs after the respondent has answered a question and after the question has been validated. In the example, it applies to respondents who click Next or Last to leave the question. The event runs the AddQuestionParadata function that performs the following tasks:
Gets the connection to the paradata database and checks whether there is already an entry for this question in this interview — that is, it tests whether the respondent has already answered this question, and might have gone back and changed the answer. (Whether or not a record exists affects the SQL query used to update the paradata database.)
Sets up an appropriate command to update the paradata database — INSERT if there is no existing record, or SELECT and UPDATE if there is already a record.
Builds a paradata record containing the following: the responses that were shown in the response list (categorical questions and loops only); the navigation button used to leave the question; the amount of time spent on the question; the number of errors; the project name; the interview serial number; the question’s full name; and the number of times the question has been asked.
Executes the command to update the paradata database with the record; that is, either inserts a new record or updates the existing record for the question.
The event ends by updating the progress bar that the interview displays.
OnInterviewEnd runs at the end of the interview and calls the UpdateInterviewParadata function. This function:
Gets the connection to the paradata database and checks whether there is already an entry for this interview in the database — that is, it tests whether this is a new or restarted interview. (Whether or not a record exists affects the SQL query used to update the paradata database.)
Sets up an appropriate command to update the paradata database — INSERT if there is no existing record, or UPDATE if there is already a record.
Builds a paradata record containing the interview properties to do with paradata. SeeUsing events to save interview paradata.
Executes the command to update the paradata database with the record; that is, either inserts a new record or updates the existing record for the question.
See also
Using events to save interview paradata