Read and Review Automation Anywhere Documentation

Automation 360

Close Contents

Contents

Open Contents

Build a custom package in IntelliJ

  • Updated: 2022/08/29
    • Automation 360 v.x
    • Build
    • RPA Workspace

Build a custom package in IntelliJ

Use Java IntelliJ to create and compile a JAR file that you can upload as a package to your Control Room in Automation 360.

Prerequisites

A basic understanding of JDK and Java IntelliJ is required in order to build an action package. Ensure you have installed the following software and files:

Procedure

  1. Download the latest release of the Automation Anywhere Package SDK. For the latest release of the Package SDK, see - Automation 360 Package Development Kit Release Notes.
  2. Unzip the contents of the SDK package to any of your local directory.
  3. Rename the folder from A360-package-sdk-<version number> to MetricToImperial.
  4. In IntelliJ IDEA, go to File > Open and open the project at C:\<SavedLocation>\MetricToImperial.
    IntelliJ File Open
  5. Open the settings.gradle file in the project root. Set the rootProject.name = 'MetricToImperial'
    Setting.gradle Project name
  6. Open the package.template file located at src > main > resources > package.template.
  7. Change the package name from A360DemoPackage to MetricToImperial.
    Rename the Package.Template name field
    Click the Sync button in IntelliJ to update the project.
  8. Update the package name in locales json: go to src > main > resources > locales > en_US.json.
    1. Open the en_US.json file and update the required label field from A360DemoPackage to MetricToImperial. Update the optional description.
    2. Delete all other remaining lines in the en_US.json file.
  9. Delete the sample packages, go to src > main > java > com.automationanyhwere.botcommand, and delete the samples.commands and delete the samples packages.
  10. Create a new package, right-click on java folder and select New > Package. Enter the new package name as metrictoimperial.commands.
  11. Create a new Java Class, right-click on the metrictoimperial.commands package, and select New > Java Class. Enter the name for the new class CMtoINCH:
    1. Open the CMtoINCH class. Copy and paste the following code above the class definition statement:
      import static com.automationanywhere.commandsdk.model.DataType.NUMBER;
      //BotCommand makes a class eligible for being considered as an action.
      @BotCommand
      //CommandPks adds required information to be dispalable on GUI.
      @CommandPkg(
              //Unique name inside a package and label to display.
              name = "CMtoInch", label = "[[CMtoINCH.label]]",
              node_label = "[[CMtoINCH.node_label]]",  description = "[[CMtoINCH.description]]", icon = "ruler_icon.svg",
              //Return type information. return_type ensures only the right kind of variable is provided on the UI.
              return_label = "[[CMtoINCH.return_label]]", return_type = NUMBER, return_required = true)
    2. Inside the CMtoINCH class, copy and paste the following code:
    //Identify the entry point for the action. Returns a Value<String> because the return type is String.
    @Execute
    public NumberValue action(
            //Idx 1 would be displayed first, with a text box for entering the value.
            @Idx(index = "1", type = AttributeType.NUMBER)
            //UI labels.
            @Pkg(label = "[[CMtoINCH.CMInput.label]]")
            //Ensure that a validation error is thrown when the value is null.
            @NotEmpty
                    Double CMInput) {
        //Internal validation, to disallow empty inputs. No null check needed as we have NotEmpty on CMInput.
        if ("".equals(CMInput.toString().trim()))
            throw new BotCommandException("Input of CM is required");
        Number result;
        try {
            //Conversion logic
            result = CMInput * 0.393701;
        } catch (Exception e) {
            //Throw custom error message
            throw new BotCommandException("Unable to convert " + CMInput.toString() + "cm to inches");
        }
        //Return NumberValue.
        return new NumberValue(result);
        }
    To import the namespaces, click the highlighted red notations and press ALT+ENTER key and select Import which automatically imports namespaces based on the annotations and datatypes.
    CMtoINCH Java Class
  12. Configure en_US.json file, go to src > main > resources > locales > en_US.json and add the following fields after the label and description values:
    "CMtoINCH.label" : "cm to inches",
    "CMtoINCH.node_label": "cm to inches",
    "CMtoINCH.description" : "Convert centimeters to inches",
    "CMtoINCH.return_label" : "Assign the Output in Inches to a Number Variable",
    "CMtoINCH.CMInput.label" : "Centimeters to Convert to Inches"

    Configure en_US.json
  13. Update the CommandPkg annotation. Download icons from Github.
    1. Download ruler_icon.svg from github and right-click the image and save the image as ruler_icon.svg.
    2. Download iconwhite.svg from github, right-click the image and save the image iconwhite.svg.
    3. Copy both files into the src > main > resources > icons folder.
      Icons for Pod
  14. Open the build.gradle in the project root. After the dependencies section, but before the last closing tag