Here are some tips and tricks to remember when working with variables:
When you rename a variable that is already in use, you should also update all existing lookups that point to the variable. A lookup that refers to an incorrect or empty variable returns the empty string ***** at a workflow's run time.
It is helpful to know when to use an initiation parameter or a variable in a workflow: Use an initiation parameter when you want the workflow to use information provided by the user, and a variable when you want the workflow to use the data generated by a workflow.
Use a variable when you want to use dynamic values throughout a workflow. For example, if you want to use a dynamic error message to be sent out in an e-mail message or logged to the History list, build the error message as a string and store it in a variable so that you can later reference it anywhere in the workflow. To take another example, if you want to use a dynamic subject line in the Define Email Message dialog box, first create a concatenated string of text and lookup values, and then store this string in a variable. You can then insert a lookup to the variable from the subject line in the e-mail message.
If you have conditions or lookups that are used frequently throughout the workflow and are not expected to change, try to store the value of the condition or the lookup in a variable. This improves workflow performance because it eliminates extra queries, and it also makes your workflow more readable.
Note When storing data in a variable, make sure that the variable always refers to a value that holds the most current data (such as a field in a list), especially when you use a delay action (Pause for Duration or Pause Until Date), a wait action (Wait for Field Change in Current Item), or a task action (Assign a Form to a Group or Assign a to-do Item). A variable will not refresh automatically if the data has changed while the workflow was paused, so it is important to make sure that the variable is always linked to a data source that holds the most current value.
You can use a variable to track what a workflow has done in early steps and then have the workflow perform an action based on the value in the variable. For example, in
a conditional branch, after a workflow creates an item in a list, you can set a variable named ListItemWasCreated of the Boolean data type to record that the item was created. Then, in a later step, you can reference the ListItemWasCreated variable in a condition and determine whether the workflow should perform an action — for example, if the item was created in the previous step, then the workflow can update the item.