SharePoint Workflow Instance Properties, MappedVariables and UserState

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

When SharePoint activates the workflow in Workflow Manager, it basically send a REST message to Workflow Management Site. Workflow Management Site is the web site hosted in IIS at http:12291 and https:12290.
The code which is running on this site will prepare so called activation message for Service Bus. In fact all magic behind SPS Workflow story is about service bus. More precisely the message will be sent to the topic which looks like:

sharepoint/default/eac2871d-0758-4a2e-8b03-c02598c63c0b/8256fccd-21e8-4435-8327-2affb3234c23.

Note  preceding sharepoint indicates the default root namespace. Do not forget that this namespace is default from SPS point of view only. Service Bus itself has a master namespace which is root for everything.
This is how you can obtain that namespace:

get-SBNamespace

.. and this is result: WorkflowDefaultNamespace

In fact when you connect to WorkflowDefaultNamespace you will see in only namespaces behind that one. This is why sharepoint appears to be a root. But it is not! We use in our projects usually one Workflow Manager (with Service Bus) which host all workflows. That means, for us, SharePoint is just one of many workflow clients. In this case we only have to take a care that we do not setup the namespace which is named “sharepoint”.

Usually when one workflow is published, the published can setup few so called external variables. These are used as input for workflow. Following code sample shows how to do that:

    Collection<ExternalVariable> externalVariables = new Collection<ExternalVariable>

            {

                new ExternalVariable<string> { Name = "Name", Default = "Damir", Modifiers = VariableModifiers.Mapped },

                new ExternalVariable<string> { Name = "Address", Default = "Frankfurt" },

            };

           

            Console.Write("Publishing Workflow...");

            client.PublishWorkflow(workflowName, @"..\..\Workflow.xaml", externalVariables);

Example above publishes the workflow by passing two external variables: “Name” and “Address”. Note that such variables are attached to workflow as metadata.
Additionally you can also use Workflow Arguments which are usually passed by starting of workflow instead of by publishing.

SharePoint 2013 use External Variables instead of input Arguments. Picture below shows two workflows with external variables. Every external variable has a key and value. The key is defined as a XName to statistically
avoid possible intersections. In a case of sharepoint this is: Microsoft.SharePoint.ActivationProperties.*.

 

image

Notice at the picture above that the second workflow has an external variable UserStatus. This one is implemented by me. That means you can extend a set of values.
This set of values is called MappedVariables and can be obtained as:

instanceInfo = client.Instances.Get(workflowName, instanceId);
var externalAndUser = instance.MappedVariables;

The list of mapped variables is consisted of External Variables (described above) and list of UserStatus variables, which can be added inside of workflow. Both can be accessed as MappedVariables. Additionally, MappedVariables of type UserStats can be accessed as follows:

instanceInfo = client.Instances.Get(workflowName, instanceId);
var status = instance.UserStatus;


Posted Nov 20 2012, 08:34 AM by Damir Dobric
Filed under: , ,
developers.de is a .Net Community Blog powered by daenet GmbH.