Difference between revisions of "Task Variables"

From PresenceWiki
Jump to: navigation, search
 
Line 3: Line 3:
 
Consider the following Task:
 
Consider the following Task:
  
http://www.international-presence.com/wikidocs/images/variable_scope_1.png
+
[[file:variable_scope_1.png]]
  
 
Here a local variable is set in the third Node. Because the Task [[Execution Path]] is linear the variable can be read by subsequent Nodes (including the Send Email Node).
 
Here a local variable is set in the third Node. Because the Task [[Execution Path]] is linear the variable can be read by subsequent Nodes (including the Send Email Node).
Line 9: Line 9:
 
However, what happens when we introduce a second execution path, like so:
 
However, what happens when we introduce a second execution path, like so:
  
http://www.international-presence.com/wikidocs/images/variable_scope_2.png
+
[[file:variable_scope_2.png]]
  
 
In this case, the value of the variable ${local} set in the 3rd Node will NOT be visible to any of the Nodes in the second execution Path, since the variable value is stored in [[Presence Context]] which only gets passed forward - not backwards. Once the first "Send Email" Node is finished execution will pass to the second Passive Node, then the second Send Email Node. Neither of these Nodes will be aware of the variable.
 
In this case, the value of the variable ${local} set in the 3rd Node will NOT be visible to any of the Nodes in the second execution Path, since the variable value is stored in [[Presence Context]] which only gets passed forward - not backwards. Once the first "Send Email" Node is finished execution will pass to the second Passive Node, then the second Send Email Node. Neither of these Nodes will be aware of the variable.

Latest revision as of 08:48, 21 August 2015

Task Variables, once set, are visible to the entire Task, regardless of the path of execution taken. This document describes the nuances of this functionality with the aid of diagrams.

Consider the following Task:

Variable scope 1.png

Here a local variable is set in the third Node. Because the Task Execution Path is linear the variable can be read by subsequent Nodes (including the Send Email Node).

However, what happens when we introduce a second execution path, like so:

Variable scope 2.png

In this case, the value of the variable ${local} set in the 3rd Node will NOT be visible to any of the Nodes in the second execution Path, since the variable value is stored in Presence Context which only gets passed forward - not backwards. Once the first "Send Email" Node is finished execution will pass to the second Passive Node, then the second Send Email Node. Neither of these Nodes will be aware of the variable.

This has important consequences for Nodes which utilize iterative execution paths such as the While Node. Any local variables set after a While Node will not be visible when control returns to the While Node itself, meaning that they cannot be used as the While test.

The solution is to use Task Variables instead of Local Variables. Task Variables are stored at the Task Container level instead of at the Presence Context level. This means that once a variable has been set with a scope of "Task", it can be read from and written to anywhere in the Task, regardless of the execution strategy. For this reason While Nodes that test the value of a variable should always use Task Variables instead of Local Variables.

See also: Variables, Global Variables