1 - Tutorial Overview
With Asternic Scripter, you can deliver a unique and personalized script, survey or questionnaire, making the process feel more like a conversation.
Some of the dynamic feature we will cover in this tutorial are:
- Conditional Routing
- Variable substitution
2 - Data Collection
In our first tutorial for a basic script, we covered how to branch a script to specific nodes based on Answers.
This is not the only way to do routing, we can also use actual form answers, or the score assigned to them, to use in logical conditions to route the script to a specific node.
We will start our script by gathering some information from our customer using some data entry fields. Based on the answers provided in the form, we will then branch to a specific part of the script.
First of all, lets create a new script with the name "Routing Demo"
In the script grid view, click on the Edit Nodes buttons on our newly created script and then click the Add button to create our first node.
The first node will be of type Question as we will need to click on a button to continue with the process, let's set the title Data Collection to it, as shown:
To continue with our script we must present the user with a continue button, that goes added as an answer in the Answers section. We will fill up that right now: click the Add Answer button, set its text as Continue
In the Link box select none so we get the quickly create a new node window pop up. This new node will be of type Logic Jump. We will use the title "Logic Jump based on age", as shown:
Click Add Node when done. The editing page will look like this once the answer is created. Note that the Continue answer will link to the 2nd node that will jump to a specific destination based on conditions we will define.
Do not click Save yet, we are not finished! We are going to add some data entry fields. Click on the Data Entry tab as shown:
We are going to ask for name and age, so click the Add Field button, we will first ask for the customer name:
It's a single line of text. With the name variable and Name label. We mark it as required also. When you are done, click the Add Field button to save it.
Then create the second data entry field, click Add Field again:
As you see we select the type Radio Buttons to give the user a multiple choice list where only one selection is valid. We marked it to be required and used the variable name 'age_range' while the label is the actual question: What is your age?
Then we entered every option available in the list options text area, one per line. We also selected the "use score" checkbox. This allow us to configure a specific variable name to hold the numeric score and in the contiguos text area labeled Scores we can the numeric score for each of the options configured.
IMPORTANT |
The score variable name must differ from the field variable name. Scripter also has a generic score variable already created for you, that you can use directly from answers that might have assigned a score to them. Also, score variables will always be numerical, as we will use arithmetic sum whenever something is set for that variable in a node. You can have a node that will set the score, and a subsequent node that will add to the same score variable. |
We chose to use numeric scores as it is sometimes simpler to use numerical conditions than textual based ones, although you could skip using scores and just use the actual option selected and the form field variable name instead for your logical conditions.
When done, click Add Field to save it. Our node will look like this:
We are done with our first node. Click Save to finish.
3 - Populating all destination nodes
This is how our script looks like for now, the Data Collection node and the quickly created Logic Jump as our only answer on the first node:
For simplicity, before editing the logic jump node we will first create the destinations where we want to land after our logic conditions are met.
Our date range has 6 options, so we will create 6 new nodes as landing nodes for each. Go ahead an click the Add button to create a new node:
This is a final/ending node, so we select type Solution, and Node Result as Success. On title we indicate something meaningful, this will be the node for people under 18. In the content we just greet the user, using the variable {name} from our first data entry field on the first node. When done, click Save.
You will have to create the rest of the nodes in a similar fashion, type Solution, title with the date range we want, and some content:
Save it as the first one, and do the same 4 more times. When done, you will have a node list like this:
We have all of our destinations ready, notice that no node links to them yet (The links in column shows empty).
4 - Age based Logic Jump
Now that we have all of our destinations in place, go ahead and edit the 2nd node that will perform the logic jump:
In this type of node we have Conditions tab as a primary section. We can enter several conditions with particular matching rules and a default route if no other rule matches. Conditions are evaluated in order, so if the 1st matches, the rest will be ignored.
Note |
Condition order can be rearranged by drag & drop. This drag & drop sorting can be done also with the Answers or Web hook sections. |
We had 6 options for our age range, so we will add 6 conditions. Go ahead, click the Add Condition button 5 times, the 6th option will be the default. You will see something like this after the process:
Now we need to populate the fields for every condition. The score variable we used in our radio buttons field was age so we will use that variable in all of the conditions. We will match with the less than operator and put the appropriate score value we used on the scores list. Finally we will select the link to the destination node we created before. Like this:
Notice that the default condition does not require to enter any particular matching operator. Once done, click Save
5 - Final Result
This script is not that useful in itself, but serves as an introduction on the powerful logic conditions we can use in our scripts. The final node grid looks like this:
Now all of the nodes except for the first node have some other node linking to them, they are not orphan. They are being used.
If you now run the script, after entering your name and selecting an age range, you will jump to the correct node, skiping the rest.
You can use this kind of logic to route a questionnaire based on previous responses.