Session initialisation
In the previous section, we indicated to Ninoxbee the name of a function in our business app that will handle the initialisation of a session for the user. This function needs to be implemented in your business app as it will allow to to track all answers for a specific form submission and attach these answers back to your business app.
In your business application (e.g Training), we will create a new function called initSession()
function getForm(_formId : text) do
first(select Form where 'Form ID' = _formId)
end;
function getSubmission(_formId : text,_submissionId : text) do
first(select Session where Form.'Form ID' = _formId and 'Session Id' = _submissionId)
end;
function getOrCreateSubmission(_formId : text,_submissionId : text) do
let s := getSubmission(_formId, _submissionId);
if s = null then
let form := getForm(_formId);
let newSubmission := (create Session);
newSubmission.(Form := form);
newSubmission.('Session Id' := generateRandomSubmissionId());
record(Session,number(newSubmission))
else
record(Session,number(s))
end
function initSession(_formId : text) do
"Expected Response";
let submission := getOrCreateSubmission(_formId, "");
{
submissionId: submission.'Session Id'
}
end;Now that we've created our session, let's move to implement the function that fetches the next question from your business app
Last updated