3d grids with last column exclusive

I was saying in a previous post it’s always better to prevent than to treat.
Here is a first example having a 3Dgrid with multi questions type. Let’s say I want the last column exclusive with the rest (per row)

Everything will happen on the client side, so we don’t have to be worried about checking data and throwing error messages back.
Plus there would be no confusion when naming a column saying “none” or “none of these” and letting the other checks too.

As usually you have to include a jQuery library and use the script below

$(".confirmit-grid tbody tr")
.each(function(index){
	var row=index+1;
	var last=$(this).find("input:checkbox").length;
	$(this).find("input:checkbox")
	.each(function(index){
		$(this).click(function(){
			if(index+1==last) 
				$(".confirmit-grid tr:eq("+row+") input:checkbox").not($(this)).attr("checked", false);
			else $(".confirmit-grid tr:eq("+row+") input:checkbox").last().attr("checked", false);
		});
	  });
});

Treat or Prevent?

It’s a pretty simple question, and most of you can definitely say to prevent is better.

If it’s so obvious preventing is better, I’m then wondering why Confirmit (and other survey software too..) isn’t.
I see internal scripts, masking, validation, throwing errors, etc. everything to make sure there’s no way a respondent will answer wrong, wrong meaning not following our instructions, the humongous text we insert to make sure he will finally get how he’s supposed to answer the question.

But.. Nothing really to prevent it, right? Confirmit has some tries lately, and this means is up to us to find different ways.

What we can do? There`s plenty of room for improvement, means that in the following posts, we will be focusing on how to improve the … of course, the user experience

Calling confirmit functions from inside the theme. Part2: dynamic content

One other possible usage of calling functions from a theme is to actually display a piece of html code dynamically created inside the survey.

Here is one example of a function that based on a question answer returns an image string:

function content(){
var content="";

if (f("q1").get()=="1") content="<img src=\"images/top1.png\" />";
else content="<img src=\"images/top2.png\" />";

return content;
}

Just place the function call in the theme,

^content()^

What will happen is that if the answer with precode 1 is selected it will return the first image if not it’s the second image returned

Based on this simple example you can come with more complex content, depending on your needs, you can also have the logic based on background variables, like language, or gender etc.

And don’t forget to deselect the option “Html encode output of piping expressions” before compiling

Automatically close a project when quota is full using Confirmit APIs (C# .NET) & JSONP – Part2

In the previous post, we’ve covered the .NET application that connects to Confirmit APIs and closes a project.
Let’s see now what we need to do in order to actually call it from a Confirmit survey.

Since the topic is close a project when the quota is reached, we’ll first need a condition node, with a quota check qf(‘quota1’)

In the “then” branch, you continue to use your own scripts, set the respondent status SetStatus(‘quotafull’) and everything else you may have, but not do the redirect yet (if you’re using one)

Add an info question type with the following content. You can use the instruction area as well.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="http://jquery-jsonp.googlecode.com/files/jquery.jsonp-2.1.4.min.js"></script>

<script>
//hide navigationarea(s)
$(function() {
	$('.navigationarea').hide();
});


function callback(data){
	//if(typeof data.status!="undefined") //you can use the data.status here
	//show navigationarea back...
	$('.navigationarea').show();

	//or redirect them to whatever URL you need
}

$.jsonp({url: "http://your domain to Confirmit Close Project/?projectID=^ProjectID()^",complete: function(data) {}});
</script>

As you can see the only parameter we send is the project ID.

There could be more to add, like showing a div with a message “Please wait!” or an ajax loading gif etc

For a better understanding on how everything works, as soon as the quota is reached, the first respondent who gets in the condition qf(‘quota1’), true now, will trigger the call to the .NET app that closes the study.
After this, it doesn’t mater how many respondents are currently on the link, no one else will made it to the end (of survey). If clicking on the “next” button, the system will answer with the standard message, “Sorry, but this survey has been closed.”

Check an older post, and find out how can you customize it for this particular study (you can also have a redirect right from the theme)

Automatically close a project when quota is full using Confirmit APIs (C# .NET) & JSONP – Part1

Surely by now, if you were in Confirmit world long enough, you must have heard questions about closing studies automatically when a quota is reached.
If you’ve ever asked to do this, I’m pretty sure the answer was Confirmit has nothing to accommodate this.

If you have access to Confirmit APIs means you can say now, I have something!

This solution comprises two parts:

  • An application (done in C# .NET) that connects to the APIs and closes the project
  • The actual call directly from inside the survey (that needs to be closed). For this I’m using a JSONP technique since you never know where the app ends being hosted, plus this offers you a little bit more control over it.

Before starting, make sure you have access to Confirmit APIs (your user has to have some special permission).

Since this is done in .NET you start by creating a new Web site and add (Add web reference) two of the Confirmit WS: LogOn and Authoring, LogOn is needed for authorization reasons.

The links to connect to the APIs are in the following format:
your_confirmit_domain/confirmit/webservices/version/service
where version is your Confirmit version like 15.0 and service is one of the available services Confirmit APIs has here is an example: LogOn.asmx

Ok so now after you’ve added them you may see something similar
Confirmit WS reference

AuthConfirm(): authenticate and get a key back.

    private bool AuthConfirm(){

        Confirmit.LogOn logOn = new Confirmit.LogOn();
        try{
            key = logOn.LogOnUser(ConfigurationManager.AppSettings["username"]
                , ConfigurationManager.AppSettings["password"]);
        }
        catch{}
        if (key.Length == 0){       // Login failed 
            Response.Write("callback({\"status\":\"error\"});"); 
            return false;
        }
        else return true;
    }

CloseProject() sets the SurveyStatus to Closed

    protected void CloseProject(string pid)
    {
        myAuth = new Confirmit.Authoring();
        mySchema = myAuth.GetProjectInfo(key, pid);

        try {
            myAuth.SetSurveyStatus(key, pid, Confirmit.SurveyStatusType.Closed);
            myAuth.Update(key, pid, mySchema);
            Response.Write("callback({\"status\":\"closed\"});");
        }
        catch
        {
            Response.Write("callback({\"status\":\"failed\"});");
        }
        
    }

Let’s put them together now

   protected void Page_Load(object sender, EventArgs e)
    {   
        string projectId = Request.QueryString["projectId"];
        if (projectId != null && projectId != ""){
            if (AuthConfirm()) CloseProject(projectId);
        }
        else
            Response.Write("callback({\"status\":\"projectId\"});");

    }

Easy method to get data back after deleting a question

In an unfortunately event one or more questions were deleted from a live project followed by a compiling task (hey, not using the “create new database” option), you’re lucky, data is still available in the system.

Depending on how you delete it, you have these options:

If it’s only “soft” deleted, or marked as deleted, just go right click on your project name/id in Designer, select the option “Show deleted”, then you can right click on the missing one(s), undelete, and compile the project again.

If you managed to delete it for good, you must insert it again in the tree, trying to make it as it was before (especially the precodes), and recompile the project.

Helper function that displays friendly alerts or help messages

Whenever you create a survey template, and plan to have it ready to use by the rest of the team, it’s always better to make sure nothing goes out of control.
It’s possible, depending of the complexity of the scripts to need to set some values, and store them in hidden questions, or any other variables you may then later use in other function calls that let’s say can control the logic or filter some questions out depending on the setup.

Even if you are very careful, and add all the instructions needed, it’s always possible to have wrong values, wrong parameters or any other silly human mistakes.

Don’t let confirmit catch the errors (if you’re lucky enough), you need to take control: checking the parameters, values, limits, and anything else you may need, plus… think of the debugging time you’ll save.

This function does not do any of them, it’s You who should add and check your specifics.
What this function does is to help you displaying friendly alerts or help messages with instructions to your fellow team members, at the time the survey is tested.

so here are some examples: the former shows the message in a div, the latter will pop up a message with your predefined instruction text

function ErrorHelp(errorMsg,fnName){
//creates a div with the content
Response.Write("<div style=\"font-size: 24px; color: red\">Error:"+ errorMsg +" in function  " + fnName + "</div>");
}

function ErrorHelp2(instructions,fnName){
//popup alert with the corresponding instructions
Response.Write("<script type=\"text/javascript\"> alert(\""+fnName + " usage: " + instructions +"\"); </script>");
}

Calling confirmit functions from inside the theme. Part1: respondent statistics

One of the feature I like in Confirmit is that you can call functions you have defined in a survey script node from inside the theme.

When it comes to automate things, they are my favorite. The reason is, calling it from the theme it makes it run every time the page refreshes, (or the submit button (back/next) is pressed).
It’s not time consuming, it’s easy and elegant. (imagine what would be to add a script node calling the function after each question or place it on every question in the validation field..)

There are lots of possible scenarios I could think off, and one good example of using this is to track the questions where the respondents were screened out or dropped out.

So let’s say you have your question IDs named q1, q2 and so on..

you only need to have:

  • two single question type named droppedlist and screenedlist sharing the same list of answers, where you have added all the question IDs. Hidden!
  • a script node with the function below
    function setLastQuestion(){
    	var questionID=CurrentForm().toLowerCase();
    
    	if (questionID.indexOf('internal')==-1){
    		f('droppedlist').set(questionID.substr(1))
    	}
    	else{
    		if (GetStatus()=="screened"){
    			f('screenedlist').set(f('droppedlist').get());
    			f('droppedlist').set(null);
    		}
    	}
    }
    
  • and the function call from your theme
    ^setLastQuestion()^

and some comments:
screenedlist will have the questions where people were screened out only if a stop (screened) node was used in the logic.
droppedlist would be the last questions they’ve answered
If there are more than one question on the same page, only the last Id
is tracked

Sorry, but this survey has been closed.

That’s the default message when you set the project status to “closed”.

Ever happened to you to just send the invites for a study, with low incidence of course, and find out there was a last minute request you forgot to add in, or worse, you discovered a huge logic issue and you actually loose data?

You need some time to fix it, and since everyone goes in and you don’t want to loose any precious sample, you may have the only solution to close it for a while, fix it, and then re-open it.

While stays closed, what the people you just invited will see?

Nothing but “Sorry, but this survey has been closed.”… hmm, not very helpful, even worse I’d say.

With just one line of code (you should place it in your theme)

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$('#Internal_Survey_closed_text').html('This survey is down for maintenance and will be back shortly.<br/>Please try again in a few minutes!');
</script>

you can get control over it, and turn the default message into a nicely one, like mine above.

Make sure there’s a div id “Internal_Survey_closed_text” by viewing the page source, if named differently just change the code with the right one.

Support “limited(Email invitation)” and “open survey” in Confirmit and store data in the same projectID

One of the pain points when starting with Confirmit is that you don’t know what all the options means

Lets start with the “web options”:

If you have a request to support a limited (or Email invitation survey that requires an uploaded respondent list with email field) and an open survey (Gives you a general link to the interview, which e.g. can be used as hyperlink on your website) you’ll see the options are excluding each other, so you can’t have both in the same time.
Wondering if this is possible? Well, it is:

Leave the survey with the option “open survey” checked.
*Script your survey as usually.
*Compile, then import the sample file, so that you can invite people in. (In the sample file, you will need at least their email address, if you plan to use Confirmit to send the invites, of course.)
And that’s everything.

Now, because it’s public and other people could get in as well we need to add some sort of control and in the same time some tracking.

First will do some conventions:
Let’s say we need to get people in from some websites, from a banner with the survey link attached
the url will look like this
theSurveyURL?source=1 (for the first website or banner)
theSurveyURL?source=2 (for the second website or second banner) and so on..

Right where the survey starts, we’ll capture the source value and store it as explained below
So we need to create a script node with these simple lines:

var source=Request("source");
/*will only store it if it's a number
1 for website 1 or first banner
2 for website 1 or second banner
...etc
*/
if (!isNaN(source))
f('source').set(source);

source is a hidden single question type
banner1 1
banner2 2
website2 3
etc

We’ve only covered the “tracking” part so far. We also need to add at least some control, so the next Confirmit node is a condition node

!f('q1').toBoolean() && (GetRespondentValue('email')=="" || GetRespondentValue('email')==null)

this means, there’s no source or source is not a number, and the respondent is not one of our sample folks who came using their Confirmit unique links
if the condition is true, send him to a block, with an info page saying “this survey is no longer available”, or something else more friendlier… and close the interview with a status screened.