Studio
2024.10
false
Banner background image
Studio User Guide - Preview
Last updated May 13, 2024

Generating code

The Generate Code feature allows you to autogenerate code anywhere within your coded automation. The generated code can originate from a comment, a specific line within your automation, or any custom prompt that you write.

To use this feature, right-click anywhere in your code, and select Generate Code, or use the Ctrl + Shift + G keyboard shortcut, and then enter your prompt into the Code Generation Window. Prompts that you use to generate code can be lines of code, comments within the automation, or any custom prompts that you design.

Generating code from a comment

You can generate code directly within your coded automation using comments. For example, consider a comment that outlines the steps of an automation such as "Open Google and click the search icon.". If you select this comment, right-click, and then select Generate Code (or if you press Ctrl + Shift + G), then the Code Generation Window opens. Additionally, you can open the Code Generation Window by either pressing Ctrl + Shift + G or prefixing your comment with the word Generate (for example: // Generate: Open Google and click the search icon).
In the Code Generation Window, you have the following options:
  • Directly click Generate to generate the code using the comment as it is.
  • Refine the comment before you click Generate.

Generating code using a prompt

You can generate code using a prompt that you engineer. For example, right-click wherever in your coded automation and then select Generate Code (or use the Ctrl + Shift + G shortcut). The Code Generation Window opens and you can now create your desired prompt for generating the code.

Implementing methods, classes, and interfaces

Generating code in Studio also involves creating implementations for methods, classes, or interfaces in your automations. For example, say you have a method, class, or interface with comments and an XML summary, but no actual code.

In this context, the Implement method, Implement class, Implement interface, or Implement local function text will appear above the method name. When you click on Implement method or any of the other variations, the system generates the requisite code for the method. Please note, this operation might result in the creation of additional methods or classes.

For this generative AI scenario, the prompt pulls from the subject name, method description (in the form of a comment above it), and comments within the method.



Tips for writing prompts

Check out the following tips for writing an efficient prompt for generating code for a coded automation:

  1. We recommend you to write prompts within a 2000 character limit.
  2. If you want to generate code in an automation scenario that involves UI Automation and Object Repository, name your Object Repository elements clearly and arrange them logically according to the application you're automating.
  3. Reference Object Repository elements within your prompts using their names as described in the Object Repository. While they don't have to match the names perfectly, prompts should be clear enough to link them to the correct Object Repository elements.
  4. Give enough context on the code that you want to generate, so that the result closely aligns to your desired scenario.

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.