In the past I have developed document workflows using SharePoint Designer and created ‘Global Vairables.’ These are variables that are global across a workflow instance as far as I am aware.
How would I create equivalent global variables in a Visual Studio Workflow project? My first idea was to create a set of fields like this in a module:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{2FE15855-3CAB-44A6-AB29-1600204FCA20}" Name="TechRev1"
MaxLength="255" DisplayName="Technical Reviewer 1" Description=""
Direction="None" Type="User" Overwrite="TRUE" />
<Field ID="{517B22A5-1B89-4C24-82BE-3D4FD99645BC}" Name="TechRev2"
MaxLength="255" DisplayName="Technical Reviewer 2" Description=""
Direction="None" Type="User" Overwrite="TRUE"/>
<Elements/>
Is this the right approach and how would I access any global variables from an ASPX form?
Having developed my workflow in Visual Studio I have come to conclusion you should use a combination of SharePoint lists and class scoped variables to retain global state in a workflow.
You should use lists when..
You should use class scoped variables when..
The data is only needed in one class
The data is of a type can be serialised (primitive types, a type marked with [Serializable]). I have one such type in my solution:
[Serializable]
public class ReviewerBag {
public Dictionary Reviewers { get; set; }
public string Moderator { get; set; }
}
If the data is needed between classes in a workflow you can still use variables but beware that each time the variable is declared in a class it will be serialised independently when the workflow becomes idle (e.g. when the workflow waits for a user to complete a task). The variables become out of sync as they are deserialised independently on workflow resume. Moral of the story is use lists to store the data in this scenario!