Node variables are global read/write variables used to store state information about a call in progress. Since Node variables are global variables, their values will persist as the call moves from Node to Node - this is a powerful feature for tracking state information about a call.
One Node variable exists for every Node in the Call Tree. The name of a variable corresponding to a particular Node is always exactly the same as the name of the Node.
Consider the example in the Quick-Start Tutorial, that Call Tree has four Nodes: Answer_Phone, Check_Response, Call_for_Bill, and Call_for_Mary. Therefore there are exactly four global Node variables available in this Call Tree: Answer_Phone, Check_Response, Call_For_Bill, and Call_For_Mary.
Using Node Variables
Node variables are used just like any other variables in VBScript. The Node variables are read/write, so they can be used on either side of an equal sign.
When the Call Tree starts, all Node variables are reset to blank. At a Question Node, the value of that Node's variable is changed to the user's response before the macro executes. At an Action Node, if a prior Node's response is matched to a response on the Responses tab, the Node's variable is changed to the matching pattern before the macro executes. The examples below will illustrate these points.
Consider the following code from step 4 of the Quick-Start Tutorial that shows the use of the Answer_Phone Node variable:
' Did the caller press something besides 1 or 2?
If Answer_Phone <> "1" and Answer_Phone <> "2" Then
' Yes, this is a mistake. Let the user know!
Speak1 = "Your response was not understood."
' Send the caller back to the start node.
GotoNode = "Answer_Phone"
End If
In this example, the second line of code uses the Node variable for the Answer_Phone Node. The user was asked to press 1 for Bill or 2 for Mary at the Answer_Phone Node. The response given at the Answer_Phone Node is saved in the Answer_Phone variable. The value of that variable is checked for validity (i.e., either "1" or "2") and the call is routed appropriately.
The code above was taken from the macro at the Check_Response Node. The Check_Response Node is an Action Node. Therefore, the value of the Check_Response variable will be set to either "1" or "2" if the user entered "1" or "2" (the two valid choices on the Responses tab of the Check_Response Node) before this macro executes. An equivalent form of the above validity check could be constructed using these facts by replacing the first two lines of code with:
' Did the caller press something besides 1 or 2?
If Check_Response = "" Then
If there is no value for the Check_Response Node variable, it must mean that the user's response was not matched on the Responses tab, and therefore the user must have entered something besides 1 or 2. Go ahead, replace the code in the Quick-Start Tutorial example as shown above and see that it still works correctly.
Node Variables are Saved to the Call History
The values of all Node variables are automatically written to the Call History at the end of every call. This feature is tremendously useful for recording precise information about every call that takes place - great for polling/surveying, gathering marketing data, and more!
The following code from step 5 of the Quick-Start Tutorial shows how Node variables can be changed to store custom data about a call:
' Prompt the user to leave a message for Bill
Record = "Please leave a message for Bill at the beep."
' Remember to say good-bye when the caller is done.
SpeakAfterRecord1 = "Goodbye."
' For the Call History, we will save a value
' for the Check_Response Node.
Check_Response = "Message for Bill"
' File this call in the "Bill" folder
Folder = "Bill"
Notice how the seventh line sets the value of the Check_Response Node variable? When this value is saved to the Call History, instead of showing "1" or "2", the Check_Response value will be something much more descriptive like "Message for Bill".