Within a Web View step, you may want to use the results of previous steps to inform the behavior of the current step. For example, you may need to calculate and display results based on prior answers.
Contents
You can get information about the current survey using the Get Current Survey Answers method of the MyDataHelps.js SDK:
MyDataHelps.getCurrentSurveyAnswers()
.then( function(result) {
console.log(result);
} );
MyDataHelps.getCurrentSurveyAnswers()
.then( function(result) {
console.log(result);
} );
This requires your Web View steps to include the MyDataHelps.js SDK. See the JS SDK Getting Started page for more details.
The getCurrentSurveyAnswers()
returns a list of step answer data: one entry for each Question and Web View step, and one entry for each of the questions within a Form step.
Each entry includes the following fields:
Field | Description |
---|---|
date |
Date/time of when the question was answered. |
stepIdentifier |
The step identifier from the survey designer. |
resultIdentifier |
This will usually be the same as the step identifier, but for form steps it will be the identifier of the specific form question. |
answers |
Depends on field type - see below. |
For Question, Form, and Web View steps, the answers
field is a collection of strings representing the step answers. A few notes about the format:
For Consent steps, the answers
field is an empty array and there are three additional fields capturing the consent details:
givenName
- The participant’s given name.familyName
- The participant’s family name.consented
- A boolean value indicating whether the participant consented.Below is sample output from getCurrentSurveyAnswers()
.
The first step is a Question step, so the step and result identifiers are the same and there is a single answer.
The second step is a Form step with two questions. Thus there are two entries with the same step identifier and different result identifiers.
[
{
"date": "2021-02-11T09:32:50.205-05:00",
"stepIdentifier": "MoodRating",
"resultIdentifier": "MoodRating",
"answers": [
"7"
]
},
{
"date": "2021-02-11T09:32:55.205-05:00",
"stepIdentifier": "Form1",
"resultIdentifier": "Question1",
"answers": [
"A", "B"
]
},
{
"date": "2021-02-11T09:32:55.205-05:00",
"stepIdentifier": "Form1",
"resultIdentifier": "Question2",
"answers": [
"2022-10-20"
]
},
{
"date": "2021-02-11T09:32:57.205-05:00",
"stepIdentifier": "Consent1",
"resultIdentifier": "Consent1",
"answers": [],
"familyName": "Smith",
"givenName": "John",
"consented": true
}
]
[
{
"date": "2021-02-11T09:32:50.205-05:00",
"stepIdentifier": "MoodRating",
"resultIdentifier": "MoodRating",
"answers": [
"7"
]
},
{
"date": "2021-02-11T09:32:55.205-05:00",
"stepIdentifier": "Form1",
"resultIdentifier": "Question1",
"answers": [
"A", "B"
]
},
{
"date": "2021-02-11T09:32:55.205-05:00",
"stepIdentifier": "Form1",
"resultIdentifier": "Question2",
"answers": [
"2022-10-20"
]
},
{
"date": "2021-02-11T09:32:57.205-05:00",
"stepIdentifier": "Consent1",
"resultIdentifier": "Consent1",
"answers": [],
"familyName": "Smith",
"givenName": "John",
"consented": true
}
]