Intro
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âŚ
âŚshould I ditch the Invoke Code for a Coded Workflow?
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.
Step 1 - Create your Coded Workflow .cs
file
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.
Step 2 - Add the Invoke Workflow File
activity to your Main.xaml
In the next step, we will immediately try it out by simply invoking the Coded Workflow as is from another XAML file.
Step 3 - Try to add a single input string to your Coded Workflow
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:
Step 4 - Write more code into your coded workflow file
Donât just use ChatGPT to give you the code like may be the case in this tutorial
Step 5 - Configure your inputs and outputs and run your code!
You have now successfully invoked your Coded Workflow .cs
file from inside of your Main.xaml
. Congratulations!
Project files for those who want to âdig inâ
HTTPRequestWithCodedWorkflows.zip (10.0 KB)
What do you think? Will you ditch the Invoke Code?
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!
Credits
I got inspired to write this short tutorial because of this reply from my colleague.