I would like to know how to return from my java code to a robotic process.

Hi everyone.

I would like to know how to return from my java code to a robotic process.

Refering the URL below, I write a program including getWorkflowParameters() method.
docs.appian.com/.../develop-java.html

■my java code

package com.novayre.jidoka.tutorial;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDateTime;
import java.util.Map;

import com.novayre.jidoka.client.api.IJidokaServer;
import com.novayre.jidoka.client.api.IRobot;
import com.novayre.jidoka.client.api.annotations.Robot;
import com.novayre.jidoka.client.lowcode.IRobotVariable;

/**
* My robot
* @author jidoka
*
*/
@Robot
public class MyRobot implements IRobot {

/**
* Server
*/
private IJidokaServer<?> server;


public void getAllRecordFromAccess() throws Exception {

Map<String, IRobotVariable> variables = server.getWorkflowParameters();
IRobotVariable rvAccessFileName = variables.get("strAccessFileName");
IRobotVariable rvGottenRecords = variables.get("rsGottenRecords");
IRobotVariable rvErrroMessage = variables.get("strErrorMessage");


try{

Connection conn=DriverManager.getConnection("jdbc:ucanaccess://" + rvAccessFileName);
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM DT_target");

rvGottenRecords.setValue(rs);

}catch( SQLException e ){
LocalDateTime ldtNoWTime = LocalDateTime.now();
System.out.println(ldtNoWTime +" : "+ e.getMessage());
rvErrroMessage.setValue(ldtNoWTime +" : "+ e.getMessage());
}


}


}

------------------------------
Also, I set 3 variables in the robot process.
・strAccessFileName : a value of MS Access file name to which is connected in order to get records in the Access'DB
・rsGottenRecords : a value of records gotten from the Access'DB
・strErrorMessage : a value of an error message my java code returns when an error arises.

<image>

I think getWorkflowParameters() and setValue() method lets myjava code return each value to a robotic process.
Are we on same page?

  Discussion posts and replies are publicly visible

Parents
  • First, to create specific java method, I would recommend you use Java Libraries instead of create a complete Java Robot.  ( https://docs.appian.com/suite/help/22.4/libraries.html ).

    But in any case (Library or Robot), I would recommended you:

    - implement the java method as @JidokaMethod, as is explained in the library documentation

    - If have output data, define the return in the method definition

    - If you need input parameters, define them as @JidokaNestedParameter

    - The result is similar to a static method where all the necessary input data is included into the params, and the output is the return of the method.

     

    For example, in your case, yo could implement this method:

     @JidokaMethod(name = "Get Records", description = "Get Records")
     public List<Map<String, String>> getRecords() {

    List<Map<String, String>> result = new ArrayList<Map<String, String>>();

    Map<String, String> record1 = new HashMap<String, String>();

    record1.put("key1", "value11");

    record1.put("key2", "value12");

    result.add(record1);

    Map<String, String> record2 = new HashMap<String, String>();

    record2.put("key1", "value21");

    record2.put("key2", "value22");

    result.add(record2);

    return result;

    }

     

    Once you publish your code, you will see the method like this

    And as you can see, you can assign the return value to a List Flow variable

    And finally, You must return basic java datatypes, like String, List, Map, etc, If you return a java.sql.ResultSet, the data won't be mapped to a Appian RPA variable.

  • Thank you.

    With you advice in mind, I will challenge the conundrum.

  • Hi

    I have a trouble that I cannnot drag the action "MYROBOT:V0.0.01" I create i custom Java code to the workflow.

    I feel uncomfortable with the display of "MYROBOT:V0.0.01".

    Is this normal?

    Refering the document below, I add the workflow library in the console.docs.appian.com/.../libraries.html
Reply Children