22.5 Coded Automation Services: Orchestrator, UI Automation, Microsoft 365 & Custom Services
Key Takeaways
Services correspond to activity packages, such as system, uiAutomation, testing, Mail, Excel, GSuite, and Microsoft 365, and are called as service.API.
BuildClient returns an HttpClient authorized for the Orchestrator API, and GetRunningJobInformation describes the running job.
uiAutomation.Open and Attach work with Object Repository descriptors (also from libraries), and Target.FromSelector supports native selectors.
Connected services use the connections object, whose connections can be overridden in Orchestrator.
Custom services are an interface and implementation in code source files, exposed through the CodedWorkflow partial class and RegisterServices.
22.5 Coded Automation Services: Orchestrator, UI Automation, Microsoft 365 & Custom Services
Core Concept: In coded automations, services are the equivalent of activity packages, and their coded automation APIs are the equivalent of activities. The exam description lists coded workflow topics: arguments, Orchestrator and UI Automation services, Microsoft 365, hybrid workflows, custom services, and imported libraries. This section focuses on the services and how they combine with low-code work.
Services and How to Call Them
| Service | Package (minimum version for coded use) |
|---|---|
system | System.Activities 23.10.2 |
uiAutomation | UIAutomation.Activities 23.10.3 |
testing | Testing.Activities 23.10.0 |
| Mobile automation | MobileAutomation.Activities 24.10.0 |
| Mail.Activities 1.22.1 | |
| Excel | Excel.Activities 2.24.1 |
| Google Workspace | GSuite.Activities 2.6.21 |
| Presentations | Presentations.Activities 1.14.1 |
| Microsoft 365 | MicrosoftOffice365.Activities 2.6.21 |
Install the activity package, then call its APIs in the form service.API(...). Parameters replace activity properties. For example, system.GetAsset("Email Address") reads an Orchestrator asset. You can also use any .NET library from nuget.org.
Orchestrator from Code
- The
systemservice offers Orchestrator-related APIs such as reading assets and credentials and working with queue items, just as the System activities do. - For Orchestrator endpoints without a dedicated API,
BuildClient()builds an HttpClient with an access token for the Orchestrator scope, so code can call the Orchestrator API directly. GetRunningJobInformation()returns details of the current job, andLog(...)writes log messages, optionally with additional log fields.
UI Automation from Code
UI Automation APIs work with Object Repository descriptors or with selectors:
var login = uiAutomation.Open(AcmeApp.Acme.LoginScreen);
login.TypeInto(AcmeApp.Acme.LoginScreen.Email, "john.doe2023@uipath.com");
login.Click(Target.FromSelector("<webctrl tag='BUTTON' type='submit'/>"));
var dashboard = uiAutomation.Attach(AcmeApp.Acme.Dashboard);
dashboard.Click(AcmeApp.Acme.Dashboard.Students);
Openstarts or opens the application at a screen;Attachconnects to a screen that is already open.- Overloads that take
IScreenDescriptororIElementDescriptoruse Object Repository elements. - Overloads that take
TargetAnchorableModelwork with native selectors, for example fromTarget.FromSelector(...)with a selector copied from UI Explorer.
Object Repository elements can come from the project or from an imported library.
Microsoft 365, Google Workspace, and Other Connected Services
Services that use Integration Service connections are reached through the connections object:
- Create the connection (for example Microsoft Office 365 or Gmail) in the same organization and tenant.
- In code, type
connections.and choose the type, such asO365Mail,OneDrive,Excel,Gmail,GDrive, orGoogleSheets. - Select the specific connection, whose name combines the folder and the account, for example
connections.Gmail.My_Workspace_john_doe_gmail_com. - Store it in a variable in one step,
var mail = connections.O365Mail.<folder>_<account>;, and call the service's APIs through it.
After publishing, the connection can be overridden in Orchestrator for each environment.
Imported Libraries
Install a library project as a package, and its reusable assets become available in coded automations:
- Object Repository elements, for use with
uiAutomation.OpenandAttach. - Workflows, both low-code
.xamland coded.cs, which you can invoke from code.
This lets one team own the UI descriptors and shared workflows while other projects consume them.
Custom Services
Register your own services to use them in every coded file of the project:
- In a code source file, declare an interface, for example
IMyServicewithDoMyMethod(). - Implement it in a class, such as
MyService : IMyService. - Extend the
CodedWorkflowpartial class in another code source file with a property, for examplepublic IMyService myService { get => serviceContainer.Resolve<IMyService>(); }. - Override
RegisterServicesto register the implementation with the service locator.
Every coded workflow can now call myService.DoMyMethod().
Before and After Runs
Coded test cases can run setup and cleanup code by implementing the before and after interface on the partial class, for example to open an application before each test and close it afterwards.
A Hybrid Design
| Part | Choice |
|---|---|
| Process flow and REFramework states | Low-code |
| Parsing, validation rules, and calculations | Code source files and coded workflows |
| UI steps | Low-code activities or uiAutomation with shared Object Repository descriptors |
| Email and files in Microsoft 365 | Connector activities, or the connections object in code |
| Shared helpers used across projects | A library with coded source files and descriptors |
Common Traps
- Looking for an
uiservice: the UI Automation service in code isuiAutomation. - Using a connection name typed by hand instead of choosing it from
connections.IntelliSense, which encodes the folder and account. - Calling
Openwhen the application is already running, instead ofAttach. - Registering a custom service without exposing it through the CodedWorkflow partial class, so coded files cannot reach it.
- Forgetting that a service is available only after installing its activity package at a version that supports coded automations.
In a coded workflow, how is the Orchestrator asset "Email Address" read?
GetAsset.Execute("Email Address")
orchestrator.Assets["Email Address"]
system.GetAsset("Email Address")
Config("Email Address")
Which UI Automation API connects to an application screen that is already open?
uiAutomation.Attach, with the screen's Object Repository descriptor
uiAutomation.Open, which always restarts the application
system.RunWorkflow
Target.FromSelector
How does a coded workflow use a Gmail connection created in Integration Service?
Through the connections object, selecting the Gmail connection by folder and account, and calling the service APIs on it.
By storing the Gmail password in a Credential asset.
Through BuildClient with the Gmail scope.
Coded workflows cannot use connections.
Sections you finish are checked off in the contents.