I am sure many of you are fond of the
Invoke Code activity, especially in situations when you just have to do something so specific that it is much easier to type it out than to use one of the default activities. I get it
This is why I want to point you towards the Coded Workflow file in the latest Studio. Creating one is super easy, and you end up with a nice blank canvas:
Now that you have seen it, you have to ask yourself a simple question…
Well, it is of course entirely up to you. However, I’d like to showcase how easy it is to work with a Coded Workflow in the latest Studio. I will do it on an example of a cross-platform project, but it is of course available on Windows projects as well.
In our small example, we will do something that is currently not possible with a standard set of activities. We will make an HTTP Request with a binary body input, which in our case will be a sample Excel file.
In fact, you can see that the only package installed in the project is the UiPath.System.Activities one; there is no need for the WebAPI package at all.
As mentioned above, you can simply go to New → Coded Workflow and quickly create one. It must be a Coded Workflow, which is important in the next step.
In the next step, we will immediately try it out by simply invoking the Coded Workflow as is from another XAML file.
To see how easy it is to pass arguments between your Invoked Coded Workflow and the Main.xaml, try adding input and output arguments in your Coded Workflow and see what happens when you save the file.
Here is a small video how this works for one single argument:
And here you can see how it works for a single as well as multiple output arguments:
Don’t just use ChatGPT to give you the code like may be the case in this tutorial
You have now successfully invoked your Coded Workflow
.cs file from inside of your
HTTPRequestWithCodedWorkflows.zip (10.0 KB)
Is the Coded Workflow file a bit too verbose when you want to run a single line of code? Probably yes. But it is surely worth giving it a try, especially given how much easier it is to write longer snippets of code in a separate file with all the extra features
And what’s more - it opens the door not only for sharing the same code across multiple places in your process but also for sharing your useful code snippets right here, on our Forum, for everyone to learn from them and to reuse.
Please share your thoughts below and let us know how we can further improve your experience!
I got inspired to write this short tutorial because of this reply from my colleague.