Updating WorkflowData from a custom workflow

Continuing in my recent theme of communicating information back from a custom workflow (see also Updating RequestStatusDetail and Passing Data via the Request Object), this post shows how you can write information into WorkflowData parameters to then use later in the workflow, perhaps putting it somewhere with the Function Evaluator, or using it in an Email Template.

The Basic Code

The code, which you will put into your custom workflow, is very simple. To start with, get the containing workflow which gives you access to any existing WorkflowData parameters:

'' Get containing Workflow
Dim containingWorkflow As SequentialWorkflow = Nothing
If Not SequentialWorkflow.TryGetContainingWorkflow(Me, containingWorkflow) Then
    Throw New InvalidOperationException("Unable to get Containing Workflow")
End If

Then add a new parameter with the data you want to communicate back out of your code:

    containingWorkflow.WorkflowDictionary.Add("MyParam", "My Value")

You can then use [//WorkflowData/MyParam]  in subsequent steps within the same FIM workflow.

Pass the Parameter to the Custom Workflow

You can make your workflow a bit more flexible if you allow the user to set the parameter name when configuring the activity.

Here I’ve added a string parameter to my workflow UI. This allows the user to enter a WorkflowData parameter while configuring the activity. The following code snippet will return a message in the parameter.

'' Write the return details if it was requested
If Me.ResultDetails.Contains("WorkflowData") Then
    Dim seperator() As Char = {"[", "]", "\", "/"}
    Dim wfkey As String = Me.ResultDetails.Split(seperator, StringSplitOptions.RemoveEmptyEntries)(1)
    containingWorkflow.WorkflowDictionary.Add(wfkey, returnMessage)
End If

1 Reply to “Updating WorkflowData from a custom workflow”

  1. i have tried this code but [//workflow/MyParam] is always returning empty any idea why?

Leave a Reply

Your email address will not be published. Required fields are marked *


*