Hello World Robot Template

The Hello World robot template will help us learn how to use the basic methods of an Appian RPA robot.

Workflow

This robot will perform the following actions: hello-world-workflow.png

start method

This method initializes the Appian RPA API objects to be used while the robot is running. It also shows how the robot parameters are received and how the log traces are sent to the console, using different levels (WARN, ERROR).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  /**
     * Action "start"
     * @return
     * @throws Exception
     */
    public void start() throws Exception {
        
        server = (IJidokaServer<?>) JidokaFactory.getServer();
        
        windows = IJidokaRobot.getInstance(this);
        
        // we set standard pause after writing or managing mouse
        windows.typingPause(PAUSE);
        windows.mousePause(PAUSE);
        
        // log parameters example
        server.getParameters().entrySet().forEach((e) -> {
            server.debug(String.format("ParĂ¡metro [%s] = [%s]", e.getKey(), e.getValue()));
        });

        // other log types availables
        server.warn("Warn example");
        server.error("And error example");

        // we set number of items
        // on an actual robot, this number can be got from an application,
        // an Excel datasheet, etc.
        server.setNumberOfItems(1);
    }

openNotepad method

This method opens the Notepad application and puts the Window in the foreground. The method shows one way to open a Windows application. In this case, the command window Run of Windows with the key sequence "Windows+R" is used.

The method code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  /**
     * Action "openNotepad"
     * @return
     * @throws Exception
     */
    public void openNotepad() throws Exception {
        
        windows.pause(PAUSE);

        // Win+R
        windows.typeText(windows.getKeyboardSequence()
                .pressWindows().type("r").releaseWindows());
        
        // we write "notepad"
        windows.typeText("notepad");
        
        // press return key using IKeyboardSequence
        windows.typeText(windows.getKeyboardSequence().typeReturn());
        
        windows.showWindow(windows.getWindow(".*([Nn]otepad|[Bb]loc).*").gethWnd(), EShowWindowState.SW_MAXIMIZE);

        // we do an explicit pause
        windows.pause(PAUSE);
    }

processItem method

This method carries out the task of writing some text in the document opened with Notepad and set the current item with result OK. It also shows an example of sending a screenshot to the execution log in the Appian RPA console.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  /**
     * Action "processItem"
     * @return
     * @throws Exception
     */
    public void processItem() throws Exception {

        String item = "this is a test";

        // we inform that we are beginning the processing of an item
        server.setCurrentItem(currentItem, item);
        
        // we write the text into notepad
        windows.typeText(item);
        
        // press return key, we use IKeyboard instead of IKeyboardSequence
        windows.keyboard().enter();

        // we inform the item processing result
        server.setCurrentItemResultToOK();
        
        // we save the screenshot, it can be viewed in robot execution trace page on the console
        server.sendScreen(String.format("Snapshot over %s", item));
    }

moreItems method

This is a simple example of a conditional action. The method returns the string "no" so the robot will continue its execution through the transition that matches this text. A conditional action must always be a method that returns a String object and doesn't receive any parameters.

1
2
3
4
5
6
7
8
  /**
     * Action "moreData"
     * @return
     * @throws Exception
     */
    public String moreData() throws Exception {
        return "no";
    }

closeNotepad method

In this case, we're closing the Notepad application with the key sequence "Alt+F4".

1
2
3
4
5
6
7
8
9
10
11
12
13
  /**
     * Action "closeNotepad"
     * @return
     * @throws Exception
     */
    public void closeNotepad() throws Exception {
        
        // press alt+F4 + pause + "n"
        windows.typeText(windows.getKeyboardSequence().typeAltF(4).pause().type("n"));
        
        // another form
        //windows.keyboard().altF(4).pause().type("n");
    }
Open in Github

On This Page

FEEDBACK