Invoke a Workflow and bring back a value?

Hi, I need to invoke a workflow from Workflow(0) to Workflow(1) and bring the value back to Workflow(0). I am having issues passing data… Whats the proper way of doing it ? I have a variable (itemNotFound)-ocr resuslt) in Workflow(1).that gets checked in Workflow(0) do I need to invoke again from Workflow(1) to Workflow(0) to pass the value ? Could someone please show .xaml example ? I have tired many times and get an error. I had a look at Using Arguments , but it did not help.

Thank you.

1 Like

Hi Gary,

No, you don’t need to invoke again back (in fact you shouldn’t - that would create a potentially infinite loop).

I think the article you linked explains it ok’ish. Look at the bottom for type of arguments - what you need is Direction being either Out (if you only want to return the value) or In/Out (if you want to send the variable, modify its value and return it).
Please note that in both cases (Out and In/Out):

  • you need to assign the value to the argument in the Workflow(1)
  • in the arguments in the invoke activity in Workflow(0) you need to provide a variable to store the value

Sample attached.

ChildWorkflow.xaml (5.7 KB)
Main.xaml (6.5 KB)

16 Likes

Thank you @andrzej.kniola ! Your help in this forum is much appreciated. Keep up the good work :slight_smile:

Thank you @Gary_K and @andrzej.kniola. I will use your Andrez’ method. In fact my workflow does loop on itself (with room for break points) and I want to use a data table which carries data between loops.

Hey, just wanted to ask - in an invoked workflow, is there way to return the workflow early rather than use a decision tree or terminating it with a throw exception/terminate activity?

It is not bringing the value back to Main flow from Child flow incase of a exception thrown in child flow though the arguments are set before the exception thrown in child flow. In my scenario, I need value from child flow to main flow for LOGGING purpose incase of exception thrown in child flow. Any solution?

No, there isn’t a return concept in WF4 outside of what you mentioned.

Correct. This is because the data transfer between contexts takes place at the end of a successful execution of that context ( = workflow). If it goes to Faulted or Cancelled state, data is not being set.

Actually I can think of 2:

  1. Throw a custom exception and handle that appropriately (that’s the main reason for BusinessRuleException’s existence).
  2. Make use of Exception.Data property to store what you need.
3 Likes

I have created 2 .xaml projects (TxnCreation.xaml and SendToBank.xaml). One transaction number is getting created in ‘TxnCreation’ script. Saved that value in .txt file using screen scrapping and write text fil. The same need to be used in second projects i.e. SendToBank script. Both projects are under same folder. Please provide the solution.

Getting below error during execution
image

Below are the 2 projects.
SendToBank.xaml (44.0 KB)
TxnCreation.xaml (100.7 KB)