Application methods and Windows forms
Application methods are single-purpose automations that you can create to use in automations, just like any out-of-the-box method. Use Application methods when automating common tasks within a single application to make the end-to-end process more efficient.
For example, you need to create a solution that logs into an application, searches for a customer, and updates the customer's address. Because these are common tasks that you are likely to use in multiple use cases, create application methods for each task and call them from external automations.
Applications have methods that are available out of the box, such as Start, Stop, Hide, and Show. The Application methods feature allows you to add your own custom methods to applications. Use application methods as building blocks that perform commonly used functions, such as Login, AccountSearch, and AddNote. Application methods are private to the application and cannot be directly used by other automations within the project. Instead, the application methods are available in the Select action dialog box, with the other out-of-the-box methods.
Application methods support the best design practice to create small, modular automations that other projects can share and reuse. Application methods help to keep projects organized, maintainable, and scalable. They also support team development.
Like automations, Windows forms can be created for an application, which means that only the automations stored alongside the application can use the Windows form and its controls.
In the following image, click the + icons to view details about the organization of a project that uses application methods:
Add an application method
You can add a new application method in the Project Explorer by right-clicking an application to access the Application Method option in the Add menu.
The name on an automation tab indicates that the application method is within the scope of a particular application. For example, the LogIn automation, created in the scope of the BankerInsight application, is called BankerInsight.LogIn.
After adding the application method, Pega Robot Studio includes the application in the Palette. External elements are not available underneath the application, such as:
- Other applications
- Automations that are not scoped within the application
For example, an automation developer adds a new application method to the project presented above. In the following image, click the + icons to see the availability of the project elements to application methods:
Default application methods
In addition to creating your application methods, Robot Studio adds the following default application methods when you add a new application or webpage. Locate the default methods in thesection of the palette.
The StartApp application verifies whether the application is running and starts it if it's not. Conversely, StopApp checks to see if an application has stopped and terminates it if it has not.
Visibility of the application method
Application methods are exposed to the rest of the project as methods on the application interface. Application methods have two types of visibility: Public and Private. An application method set to Private is usable only in the scope of an application itself, such as by other application methods. If your application method needs to be available outside of the scope of an application, set the Visibility type to Public. The automation needs to have a defined entry point.
You can also use publicly visible application methods in automations that are out of the scope of an application. For example, an automation developer wants to use the AddTransaction application method in the main automation of the project. The developer includes the application to access the method and then drags the main control of the application to the automation surface. The application method is then available in the Select action dialog box, as shown in the following figure:
Move the application method
To move an automation under an application, ensure that you have no dependencies on global components, other applications, or automations. For example, if your automation uses a Microsoft Office connector that is stored in your Globals, Pega Robot Studio notifies you that this operation is not allowed because of dependencies.
Name automation methods
The name of the application method needs to be unique only within the scope of the application. In the following example, three automations are named LogIn, but each exists within a different scope.
Note: If you try to add an automation named LogIn in the Expense Tracker folder, you will receive an error because the folder is in the global scope, and this name would not be unique.
An application method's name cannot conflict with out-of-the-box method names for the application. The system will prompt you with an error if you attempt to name an application method with one of the reserved method names.
Return values in an application method
When running an application method, you do not have information about whether an automation completed successfully. For this reason, it is a best practice to include a Boolean return value indicating the status of the application method. To implement Boolean return values, use Labels and Jump To blocks in the application method to set the value, True for a successful operation and False for a failed operation, and pass that value to the Exit block.
Adding Boolean return values to the application method allows you to properly route the automation to handle errors. The following image shows an automation where a failed log-in is routed to the Failed label.
Application Windows forms
The automation developer can also create an Application Windows form. To add a Windows form underneath the application, right-click the application name and select Add > Application Windows form.
The Application Windows form is available only in the automation methods Include menu.
Check your knowledge with the following interaction: