22.4 Coded Automations: Structure, Arguments & Invoking Workflows
Key Takeaways
Coded automations come as coded workflows, coded test cases, and code source files, in Windows and Cross-platform projects.
Coded workflows inherit the CodedWorkflow partial class (from UiPath.CodedWorkflows), with one [Workflow] or [TestCase] entry point per file.
In arguments are method parameters, Out is the return type (a named tuple for several), and a name used in both is In/Out.
Low-code workflows call coded ones with Invoke Workflow File; coded workflows call others with the workflows object or RunWorkflow.
Use coded files for complex logic and .NET libraries, and low-code for reviewable process flow; coded automations cannot be remote debugged.
22.4 Coded Automations: Structure, Arguments & Invoking Workflows
Core Concept: Coded automations let you write automations in C# inside a Studio project, next to low-code
.xamlworkflows. They use services, which correspond to activity packages, and their coded automation APIs, which correspond to activities. Coded and low-code workflows can invoke each other.
The Three Types
| Type | Purpose | Entry point |
|---|---|---|
| Coded workflow | A workflow written in C# | A method attributed [Workflow] |
| Coded test case | A test case written in C# | A method attributed [TestCase] |
| Code source file | Helper classes, models, interfaces, and custom services used by other coded files | None |
Coded automations are available only in Windows and Cross-platform projects. Types defined in code, such as enums, can also be used as inputs in low-code workflows.
Structure of a Coded Workflow
using UiPath.CodedWorkflows;
namespace MyProject
{
public class ApproveLoan : CodedWorkflow
{
[Workflow]
public bool Execute(double loanRate)
{
Log($"Evaluating rate {loanRate}");
return loanRate < 0.08;
}
}
}
- Namespace: generated from the project name, plus the folder name for files in folders ("My project" becomes
Myproject, and a file in folder "place" usesMyproject.place). - Base class: coded workflows and test cases inherit the
CodedWorkflowpartial class from the UiPath.CodedWorkflows package, which inheritsCodedWorkflowBase. Because the class is partial, you can extend it in a code source file, for example to add properties for custom services. - Entry point: the method is named
Execute()by default and attributed[Workflow]or[TestCase]; you can rename it as long as the attribute stays. Only one entry point is allowed per file. - Package: UiPath.CodedWorkflows is added automatically when you create a coded file, or when a new project uses version 23.10 or later of packages such as System, Testing, or UIAutomation activities.
Useful base-class members
| Member | Use |
|---|---|
Log(message, level, additionalLogFields) | Write a log message, optionally with extra log fields |
RunWorkflow(path, inputArguments, timeout, isolated, targetSession) | Invoke another workflow and get its output and in/out arguments |
RunWorkflowAsync(...), Delay(...), DelayAsync(...) | Asynchronous invocation and waits |
BuildClient(scope) | An HttpClient with an access token, for calling Orchestrator's API |
GetRunningJobInformation() | Information about the running job |
services | Access to built-in services such as logging, the Orchestrator client, and workflow invocation |
Arguments
Arguments are declared on the entry point method:
| Argument kind | How to declare it | Example |
|---|---|---|
| In | Method parameters | public void Execute(string customerName, decimal loanAmount) |
| Out | The return type | public bool Execute(double loanRate) |
| Several outputs | A named tuple as the return type | public (double loanAmount, string financialNeed) Execute(double interestRate, double loanAmount) |
| In/Out | A name that appears as both parameter and output | loanAmount in the tuple example above |
An argument named Output is always treated as In/Out.
Invoking in Both Directions
Low-code to coded
Use Invoke Workflow File and select the .cs file. In Windows projects, change the file filter from workflow files to All Files to see .cs files. With System.Activities 24.10 and later, the coded workflow's arguments are imported automatically into the activity.
Coded to low-code (or coded)
workflowsobject: strongly typed calls to the project's workflows, for exampleint result = workflows.Increment(random);.RunWorkflow: pass the file path and a dictionary of inputs; the result dictionary holds the outputs:
var outputs = RunWorkflow("Workflows\\OpenTerminal.xaml",
new Dictionary<string, object> { { "in_TransactionNumber", "TXN-88412" } });
var token = outputs["out_SessionToken"].ToString();
When to Choose Coded or Low-Code
| Situation | Better fit |
|---|---|
| Complex data transformations, algorithms, or reusable helper logic | Coded |
| Integrating .NET libraries from NuGet | Coded |
| Process flow that business stakeholders review, such as REFramework states | Low-code |
| Quick UI automation with visual recording and validation | Low-code, or coded with the Object Repository |
| Teams that review changes in Git diffs | Coded files diff and merge more easily than XAML |
Most projects mix both: low-code for the process skeleton, coded workflows or source files for the heavy logic.
Worked Example: Moving Validation Logic into Code
An invoice performer has a 60-activity low-code workflow that validates line items with nested loops and If activities. The team:
- Creates a code source file with an
InvoiceLineclass and aLineValidatorhelper that returns a list of problems. - Creates a coded workflow
ValidateInvoice.cswhose entry point ispublic (bool isValid, string reason) Execute(DataTable lines), so it has one In argument and two Out arguments. - Replaces the old workflow in Process.xaml with Invoke Workflow File pointing to
ValidateInvoice.cs; the argumentslines,isValid, andreasonare imported automatically. - Throws a BusinessRuleException in Process.xaml when
isValidis False, so REFramework still marks the item as a business exception. - Adds a coded test case that feeds sample lines to the validator and checks the result with the testing service.
The process flow stays visible in low-code, while the validation logic becomes shorter, testable, and easy to review in Git.
Limitations to Remember
- Coded automations cannot be remote debugged.
- One
[Workflow]or[TestCase]entry point per file. - Coded automations require Windows or Cross-platform projects, not Windows - Legacy.
How are an input argument and an output argument declared for a coded workflow's entry point?
Inputs as properties with an [Input] attribute, outputs with an [Output] attribute.
Inputs as method parameters and the output as the method's return type.
Both in the project.json file.
Both as public fields of the class.
A coded workflow must call a low-code workflow named Increment.xaml and use its result. Which options are documented?
Only Start Process with the robot executable.
Only by publishing Increment.xaml as a separate process and starting it as a job.
Through the strongly typed workflows object, or through RunWorkflow with the file path and an input dictionary.
It is not possible; coded workflows can only call other coded workflows.
Which statement about coded automations is correct?
A file can have several [Workflow] entry points.
Coded automations are available in Windows - Legacy projects.
Coded automations can be debugged on a remote robot.
Only one [Workflow] or [TestCase] entry point is allowed per file, and coded automations cannot be remote debugged.
Sections you finish are checked off in the contents.