Web View Steps

Web View steps allow you to present customized steps within a MyDataHelps survey. Although you can use most SDK methods from Web View steps, these methods are specifically used to control the logic of your custom step.

Complete a Web View Step

MyDataHelps.completeStep(optionalAnswerText)

Complete the current survey step. If called with a parameter, that parameter is saved as the answer for the step. If no parameter is supplied, then an empty string is saved as the answer. You can also store structured data such as JSON, as long as it’s formatted as a string. See Saving Survey Results for details.

Parameters

answerText string

The single answer to record for this step. If omitted, an empty string is recorded as the answer for the step.

Availability

MyDataHelps Views
MyDataHelps Embeddables
Web View Steps
Completing a Step
<script type="text/javascript">
	function next() {
		var element = document.getElementById("StepInput");
		var answerText = element.value;
		MyDataHelps.completeStep(answerText);
	}

	function skip() {
		MyDataHelps.completeStep();
	}
</script>
<input type="text" id="StepInput" placeholder="Answer text" />
<button onclick="next()">Next</button>
<button onclick="skip()">Skip</button>
<script type="text/javascript"> function next() { var element = document.getElementById("StepInput"); var answerText = element.value; MyDataHelps.completeStep(answerText); } function skip() { MyDataHelps.completeStep(); } </script> <input type="text" id="StepInput" placeholder="Answer text" /> <button onclick="next()">Next</button> <button onclick="skip()">Skip</button>

Get Current Survey Answers

MyDataHelps.getCurrentSurveyAnswers()

Used within a Web View step to retrieve the participant’s responses to other Question, Form, Consent, or Web View steps within the current survey.

Returns

Promise<CurrentSurveyAnswers[]>

Resolves to a results collection containing a list of current survey answers.

results[n].date date

Date/time of when the question was answered.

results[n].stepIdentifier string

The step identifier from the survey designer.

results[n].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.

results[n].answers varies

Availability

MyDataHelps Views
MyDataHelps Embeddables
Web View Steps
Getting Current Survey Answers
MyDataHelps.getCurrentSurveyAnswers()
	.then( function(result) {
		console.log(result);
	} );
MyDataHelps.getCurrentSurveyAnswers() .then( function(result) { console.log(result); } );

Get Survey Context

MyDataHelps.getSurveyContext()

This method reports how the Web View step is being run, so you can alter the rendering depending on the context. Possible contexts are:

  • Design - Displayed in the static MyDataHelps Designer survey editor pane.
  • Preview - Running in the “Try It Out” preview mode within MyDataHelps Designer.
  • Survey - Running for participant data collection on any platform, including coordinator surveys in MyDataHelps Designer.

For example, you may wish to bypass a data request in contexts where a participant access token is not available (Design/Preview), and instead return sample data to drive a preview of what the step would look like.

Returns

Promise<SurveyContext>

Resolves to a result object containing the survey context.

result.surveyMode string

The current survey mode: Design, Preview, or Survey.

Availability

MyDataHelps Views
MyDataHelps Embeddables
Web View Steps
Getting Survey Context
MyDataHelps.getSurveyContext()
	.then( function(result) {
		console.log(result);
	} );
MyDataHelps.getSurveyContext() .then( function(result) { console.log(result); } );