Search code examples
c#xamlworkflowworkflow-foundation-4workflow-foundation

WF - How to get the WorkflowInvoker result from a XAML workflow


I have a simple workflow in XAML composed by a sequence and a custom activity. In the future there will be more activities. The XAML is the following:

<Activity mc:Ignorable="sap sap2010 sads" 
...
  <Sequence sap2010:WorkflowViewState.IdRef="Sequence_1">
    <local:CoefficientWorkflow sap2010:WorkflowViewState.IdRef="CoefficientWorkflow_1">
    </local:CoefficientWorkflow>
    <sads:DebugSymbol.Symbol>d11DOlxGQU1FMlxQcm9qZWN0MDJcRkJTXFdlYkFwcFxNb2R1bGVzXEZCUy5BTE9cc3JjXEZCUy5BTE8uV29ya2Zsb3dcV29ya2Zsb3dzXEFsb1dvcmtmbG93LnhhbWwDKwM0DgIBASwFMiECAQIvCy9KAgED</sads:DebugSymbol.Symbol>
  </Sequence>
  <sap2010:WorkflowViewState.ViewStateManager>
    <sap2010:ViewStateManager>
      <sap2010:ViewStateData Id="CoefficientWorkflow_1" sap:VirtualizedContainerService.HintSize="200,22" />
      <sap2010:ViewStateData Id="Sequence_1" sap:VirtualizedContainerService.HintSize="222,146">
        <sap:WorkflowViewStateService.ViewState>
          <scg:Dictionary x:TypeArguments="x:String, x:Object">
            <x:Boolean x:Key="IsExpanded">True</x:Boolean>
          </scg:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
      </sap2010:ViewStateData>
      <sap2010:ViewStateData Id="FBS.ALO.Workflow.Workflows.AloWorkflow_1" sap:VirtualizedContainerService.HintSize="262,226" />
    </sap2010:ViewStateManager>
  </sap2010:WorkflowViewState.ViewStateManager>
</Activity>

I invoke the workflow with the following code:

WorkflowInvoker invoker = new WorkflowInvoker(workflow1);
var result = invoker.Invoke();

At the moment the result variable contains an empty dictionary after invoking the workflow. As the activity contained in the sequence returns a value, I need your help to grab the output of that activity and expose externally as result of the whole workflow.


Solution

  • The result will hold an output dictionary.

    The keys for the dictionary are any OUT Arguments you created in your workflow at the workflow level.

    The value returned by the Activity must first be passed from the Activity into a Workflow level OUT Argument.
    You do this by creating an OUT Argument in the Activity and assigning it to the OUT Argument in the Workflow using the Activity Properties dialog in Visual Studio