Complex automations

Problem

SurveyMonkey Apply has a limited list of conditions possible for automations. Notably, automations can't be triggered based on less than or greater than, just equal to or not equal to.  

Solution

Create a hidden field to trigger the automation, then use JavaScript to populate it.

Skills needed

This solution assumes that you know how to create a form and an automation.

Experience using your browser's developer tools is helpful. Basic instructions for Chrome included.

Step 1: Prepare Automation Logic

Determine which question(s) will contain the information you use to trigger your automations. 

  • All questions should be in the same form. (If they aren't, you should use piping to bring the responses to a prior form into hidden variables in this form.) 
  • Make sure questions to be used have clear identifiers, since you'll be typing them into JavaScript.

Step 2: Create a Hidden Field

Obviously it does not matter where in the form you place it. It's hidden.

Give the hidden field a clear identifier and name. Use the same name in both to make your life easier.

Leave the value blank.

Step 3: Find Field ID

Preview your form and locate the hidden field (which will be visible in this view). Use your Developer Tools or view source to locate the id for the field.

In Chrome

  1. Right-click on the field and select Inspect:

  2. The inspection panel should open directly to the correct line. The id for the field will be in the format id_ZZZZZZZZZZ:

Step 4: Create JavaScript

The JavaScript question type requires that you type JavaScript code. Most automations can follow this basic template:

$(function(){ 	
var $variablename = {{ QuestionIdentifier }} ;   
if ($variablename < 100) {
	document.getElementById('id_ZZZZZZZZZZ').value = 0;
} else {
	document.getElementById('id_ZZZZZZZZZZ').value = 1;
}
});

Line 2 uses in-form piping assign the value of the question QuestionIdentifier to a new JavaScript variable $variablename. Modify as needed, and if you are using multiple questions to trigger your automation, repeat this line for each one.

This template does a simple less than comparison. Need something more complicated?

Warning

In Chrome, the form editor starts acting strange after a JavaScript question is created. Don't panic. Just save the form, exit, and enter again.

Step 5: Create Automation

You can now proceed as normal, using the value of your hidden field as the basis for your automation.