Building Patterns: The smart SharePoint questionnaire

A questionnaire that does something more than record answers

RePosted by Start Bootstrap on Jan 6, 2017

The smart SharePoint questionnaire

I am hoping that this will be the first in a series identifying common problems and offering an open solution to said problems. I expect in this series to offer solution accelerators with pseudo-code, working libraries, partial implementations etc Ok, let’s get started.

The common problem:

You need to ask as set of questions and then do some action based on the results of the answers to the questions

In concise terms, the recurrent situation is the need to dynamically navigate users through a set of questions then do something based on the answers. This breaks down as:

1. Ask a variable set of questions interweaving rich content to assist in the answering of questions
2. Calculate and record answers.
3. Upon completion, compile results, and take some actions like a workflow or building of a structured document.

Requirements & Constraints:

Must be maintained without developers
Role: User
  • Questionnaire Subjects
  • Answer questions in surveys
  • Some action happens upon completion
Role: Analysts
  • Define questionnaire
  • Creates list of questions
  • Defines questions
  • Writes question text
  • Picks question type (yes/no, multiple choice, free text)
  • answers for multiple choice

Must be built on SharePoint… Cause that’s what I wrote it for, though the it’s easy enough to switch out the method that loads the model.

Technical Solution:

The technical part of the solution is pretty straight forward; an open JavaScript object named smartQuestionnaire. The high level flow is as follows:

                    Function init(){
 	                    loadQuestions()// intended to be extended
 	                    loadAnswers()// intended to be extend
                        mapAnswersToQuestion()// intended to be extended and is run upon completion loadAnwsers
                        getFirstQuestion()//intended to be extended
                        qControl()//manages flow of questionnaire 
                    Function qControl(){// manages flow of questionnaire
                    	getQuestionHTML()//could to be extended, writes HTML content for question
                		myHTMLCtn()// intended to be extended, writes answer collection HTML
                        //attaches click event to move on to text question
                    	pushCalculatedAnswer()//intended to be extended, validated and performs answer calculation
                    	//determines if questionnaire is complete 
                    	addUpAnswer()//Must be extended , does whatever you need it to upon completion 

Persistence is straight forward too. Everything is maintained in SharePoint lists loosely modeled as follows:

SharePoint is very useful for this common problem especially given the constraint that analysts need to maintain the questions and calculations. To complete the solution, I normally end up making two more artifacts:

  • 1. An administrative page that shows a view of the questions, a connected view of the answers
  • 2. A .txt file that contains a call to my extended version of the smartQuestionaire object so that they can easily add surveys to any page they want