Getting the next question

Now we add the function responsible for getting next available question based on all previous answers.

function getQuestion(_formId : text,_submissionId : text,_questionId : text) do
		let training := first(select Training where 'Submit ID' = _submissionId);
		if _questionId = "" or _questionId = null then
			first(training.Questions[Question.Type != 1 and Question.Type != 2 and not _ANSWERED])
		end
end;
function _getNextQuestion(_formId : text,_submissionId : text,_currentQuestionId : text) do
	let training := first(select Training where 'Submit ID' = _submissionId);
	if _currentQuestionId = "" or _currentQuestionId = null then
		let firstQuestion := first(training.Questions[Question.Type != 1 and Question.Type != 2 and not _ANSWERED]);
		if firstQuestion != null then
			firstQuestion._JSON
		else
			{
				type: "end",
				label: "Thank you",
				description: "We thank you for your submission",
				imgUrl: "",
				progress: 100
			}
		end
	else
		let currentQuestion := first(training.Questions[Question.'Question ID' = _currentQuestionId]);
		let nextQuestion := first(training.Questions[number(ID) > number(currentQuestion)]);
		if nextQuestion != null then
			nextQuestion._JSON
		else
			{
				type: "end",
				label: "Thank you",
				description: "We thank you for your submission",
				imgUrl: "",
				progress: 100
			}
		end
	end
end;
function getNextQuestion(_formId : text,_submissionId : text) do
	_getNextQuestion(_formId, _submissionId, "")
end;

In the above call, we implement the logic to retrieve our next question. The simplest integration can be as getting the next question having an ID > than the current question ID, the most complex scenarios will leverage all the power of ninox to apply very complex business logic in order to fetch the exact next question. Ninoxbee leave full control over this part to the business app developer. The only thing that is needed in return is the following object format

A working example of this question can be found in the Training App.

For our particular cas, we need the end user to answer a Select question, which is represented by a single select field inside ninox. The section below is an example of a select field seen in the question object. A select hold an array of several options, each having a label, a value, and a small description field below the option.

Last updated