Answering a question

The answerQuestion is the last mandatory function you'll need to implement. The following is a sample implementation

function answerQuestion(_formId : text,_submissionId : text,_questionId : text,a : any) do
	let form := getForm(_formId);
	if form = null then
		{
			status: "ko - form not found"
		}
	else
		let submission := getSubmission(_formId, _submissionId);
		if submission = null then
			{
				status: "ko - submission not found"
			}
		else
			let answer := (create Event);
			answer.(Session := submission);
			let body := {
					formId: _formId,
					submissionId: _submissionId,
					questionId: _questionId,
					answer: a
				};
			answer.('Answer ⚡️' := text(body));
			// YOUR ANSWER PROCESSING LOGIC
			answer.(Status := 2);
			let q := _getNextQuestion(_formId, _submissionId, _questionId);
			q
		end
	end
end

The function expects 3 text fields and a Json object as parameters keeping the process the most generic.

Last updated