When an Essentials Workflow transmits state from server to client, any variables currently in scope must be included in that state. This is achieved through a process called serialization. Any objects in memory are packaged up, and send from the server to the client, or from the client to the server.
To understand serialization, we need to understand the difference between the different kinds of workflow activities:
What is an Activity?
An activity, is any of the items from the toolbox in workflow designer, that you can use in your workflow. Alert boxes, query tasks, and display forms are all examples of workflow activities.
What are client side activities?
Client side activities are any activities that run exclusively on the client side (IE on the workstation, smartphone, or tablet). Client side activities typically (but not always) involve some form of user interaction. Some examples of client side activities include:
- Alert Box
- Display Form
- Capture Geometry
- Get Browser URL
- Refresh Map
More examples can be found in the workflow designer toolbox (under the common client section)
What are server side activities?
Server side activities are activities that run on the server side, as opposed to the client side. Server side activities are usually function in a more "behind the scenes" fashion, and don't receive direct input from the user (although they may rely on indirect input supplied by user submitted client side activities). Some examples of server side activities include:
- Download Image
- Read File/Write file
- Get Current User
More examples can be found in the workflow designer toolbox (under the common server section)
Why does this matter?
When a workflow reaches a client side activity, it will package up all of the variables in the current variable scope, and the parent scope(s), then send them to the client. The client runs the activity, manipulates any variables, and then sends everything back to the server. If you have any variables that are used by server side activities in your workflow, but do not need to touch the client at all, it does not make sense to send these every time you need to switch back and forth from a client activity to a server activity. This can impact performance, especially if you are dealing with a lot of variables.
To solve this issue, you can scope your variables to certain sections, so that only the needed variables are send to the client or server. For example:
In this screenshot, we can see a flowchart based workflow (A). We can see that we have a single variable assigned to the Flowchart scope (B) called GlobalVar1. We can also see that we have 2 sequences, ClientSideSequence (C), and ServerSideSequence (D). We'll get into these in a moment, but for now the important part is that when we have the Flowchart selected, we can see the global variable, which is scoped to the flowchart activity.
Now watch what happens when we select the ClientSideSequence (A). Now we can see 2 variables. We can still see the GlobalVar1, since it's scoped to the main sequence, but we can also see a new variable that we couldn't see before (B). This variable is specifically scoped to the ClientSideSequence (C), so any activities we have inside that sequence will be able to see and manipulate that variable. When a client side activity executes, and the variables are serialized, the contents of ClientVar1, and GlobalVar1 will be sent to the client.
Now, when we select the ServerSideSequence (A), we can no longer see the ClientVar1 variable, since it was only scoped to the ClientSideSequence. We can instead see a new variable, ServerVar1 (B), which is scoped to the ServerSideSequence (C). When we are finished executing the client side activities in the ClientSideSequence, and we move on to executing the activities in the ServerSideSequence, the content of ClientVar1 is discarded, since it is not in the new scope. The content of GlobalVar1 is preserved. Since it exists in both scopes, it can be serialized, and transmitted from the client side to the server side.
A workflow's variables will be serialized when it is transferred from server to a client (and back again). Many errors can be avoided if care is taken when assigning the scope of a variable, and ensuring that only the minimum amount of data is being transferred.