I would like to know if there is any JS API we can use, when the next button is clicked, to stop(or delay) the page submit to execute some of our custom functionality.
Page 1 / 1
What specifically are you trying to do? Would the .addonUnload section not accomplish this?
!
!
Below is the code snippet I am trying to do:
Qualtrics.SurveyEngine.addOnUnload(function(type)
{
var clientId = 'ClientId';
var userId = 'UserId';
var password = 'password';
var surveyId = "${e://Field/SurveyID}";
var responseId = "${e://Field/ResponseID}";
var pageId = "P1";
var matrixData = getMatrixData();
CollectData(clientId, userId, password, surveyId, responseId,pageId,matrixData);
function getEngagedResult(jsonData) {
if (jsonData.Success) {
alert(jsonData.Success);
//The page submit should wait till this block is reached
} else {
// check jsonData.ErrorMsg
}
}
});
Qualtrics.SurveyEngine.addOnUnload(function(type)
{
var clientId = 'ClientId';
var userId = 'UserId';
var password = 'password';
var surveyId = "${e://Field/SurveyID}";
var responseId = "${e://Field/ResponseID}";
var pageId = "P1";
var matrixData = getMatrixData();
CollectData(clientId, userId, password, surveyId, responseId,pageId,matrixData);
function getEngagedResult(jsonData) {
if (jsonData.Success) {
alert(jsonData.Success);
//The page submit should wait till this block is reached
} else {
// check jsonData.ErrorMsg
}
}
});
Change addOnUnload to addOnPageSubmit. The question data on the page will already be gone by the time addOnUnload executes.
I tried doing that but next page loads before i receive response from the third party API I am calling. I need to stop navigating to next page until i receive the response(success) from the other api.
You could put next question in a new block and call the third party API with with web service from the survey flow.
Not sure on the web service from survey flow, but for now, I am trying to use an empty page/block(a descriptive question asking survey responses to hang on), store response from previous page/block in session, hide next button, submit them in page load and click next button when response is received. If that does not work out, I will go with web service call. Thanks a lot, TomG.
Hi TomG, my requirement is to add few hidden variables in the page/block with an open ended question, when the next button is clicked, submit the values of open ended text area and the hidden variables to third party api, set the response values from third party api into embedded data. Can you elaborate more on the suggestion you were providing with web service?
A web service call is perfectly suited to what you are trying to do. You can add the hidden variables directly to the web service as parameters, then pipe the question text value into the web service as another parameter. As long as the third party api returns json or xml, the returned data will populate embedded variables.
Here is information on adding a web service to your survey flow.
Here is information on adding a web service to your survey flow.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.