E9.2 Connect to another database and insert into JDE - ORCH

Lennon2

Member
Hi , I'm creating a small ORCH to connect with other database, this step was working ok
but Insert in JDE I get an error , I think that the problem is how clean the JSON.


EXERCISE
Get the largest number from a table in another database and insert it into F55xxxx JDE


========== Step 1 ==========

Create Connector and connection to another database - OK
AD_4nXdGYYDmGzabHvWQb89yvGD9ZSfo7sSicqXrouI3YczZX4Qrm5J2SCJy2oNXd-uE0pWMQgo8N88fvATFLN3ZUKruQo0Xe9fwAQO7MSP-ORpag4_SOSxrVmrfqn3vhjXFlvlno0nPsyC00Rw7rb8NDIKRZIg


Groovy Script Connector - with Query SQL

import groovy.transform.CompileStatic;
import com.oracle.e1.common.OrchestrationAttributes;
import java.sql.*;

@CompileStatic

HashMap<String, Object> main(OrchestrationAttributes orchAttr, Connection sqlConnection, HashMap inputMap)

{

HashMap<String, Object> returnMap = new HashMap<String, Object>();

//define the select statement
def selectStmt = "SELECT MAX (ALHONB) FROM XXXXXXX.XXXXXXX WHERE ALC0ST= '9'";
def firstDockID = "";

//create a prepared statement with the SQL
PreparedStatement preparedStmt = sqlConnection.prepareStatement(selectStmt);

//execute the query returning the result set
ResultSet resultSet = preparedStmt.executeQuery();

//use the helper to set the records from the result set to the array variable
returnMap = orchAttr.mapResultSetToDataSet(resultSet,"ALHONB");

List<String> dataset = (List<String>) returnMap.get("ALHONB");
firstDockID = dataset.get(0);

//close the result and statement
resultSet.close();
preparedStmt.close();

return returnMap;
}


Output Connector
AD_4nXfIWrjxA8tM2SZv1uvIOsIt9GB-ftaNXvP_VZEA45xr5YVMCnbDtJlL-mfjhxxRvERm7XrOGK3uUGlrz2K0ca0pAtbfJQItODZ2ZSQe7v4H3QWtvXtA3KB_qfxnCgNxPfiYOQMrPBmFqQ1mzPREUEtTGoTC


======== STEP 2 ========
Run the Orch - OK

response
AD_4nXeXBCcDsvsRoTdu8CZ4W2vabjCjT6EsD71_eZic3kT-J2giBhVfrXhpViJ7O3OTPenQE2G58mdGvk22NnQTuwffoniR_CFmZn1oizk9MGRD0i6v4Eec4creUljAzxdS038YZGkD6TrgVQ2JOovM76VT4YNK


The number obtained is correct, it is the 682217



===== STEP 3 ========
Insert this Number in for example a table F55xxxx like DOCO

I created a NER to insert the number and the parameter is DOCO , add the function on the ORCH and setup the parameter.

AD_4nXeY1iFYg4A2OGCAW5CTcNlmKitoGbAn6D2lvzfvSh5bVdl2lhxAgb09tpytf6q94uztRB6nbg7mn7ZRQ1rdyuAVImCp63OMUekY4IyUSkVuTekpa7bpJ5ZK4ZDGH5iGIjMU5IEO4kHyRImNOSyOUVsO2i1J


Mapping in the Function the output Conector (ALHONB)
AD_4nXfYhTQ21ksFE7PP0fWxmyLBcu1qDhA9JQGGR6sC8EjS2E-pEluhFvGcIHQ2A1FTwJ_KLYEqdMWKGw-wBgGXakuYsCONfWhBkfyqzp7jG8A1Gyd_RmbLv-Olal0e3ihvHpuqMqWkEDxK-COtgryjdCyTxqI




========STEP 4 =========
AD_4nXdlXE8XeZjstiV_PKHjk7AthSFZXAmE8KMzP_0bg0hAg6xEiHbZxYV5xTYm2s7ePmRG_v4AFU8vBP4w6iVeNZAN27vlbLLki1DtQrr0KCuyzvbb3yMiOGlPlGulcx37yKKXOWswjXj4mUKvgKXvqdaGTvny


What is the best way to clean the JSON to get the DOCO and be able to insert it without errors what am I doing wrong?
thanks in advance
 
The output from your database connector is what will be returned to the orchestration. You are defining your returnMap as:

//use the helper to set the records from the result set to the array variable
returnMap = orchAttr.mapResultSetToDataSet(resultSet,"ALHONB");


So what you are sending back to the orchestration is the entire result set in an array called ALHONB.

What I would do is not map the resultSet to the returnMap, but to a different variable (let's use dataset for example).
dataset = orchAttr.mapResultSetToDataSet(resultSet,"ALHONB")

Then I would add:
returnMap.put("ALHONB",dataset["ALHONB"][0])

This will add ALHONB to returnMap with the value you are looking for.

This code is not needed, though you were heading in the right direction.
List<String> dataset = (List<String>) returnMap.get("ALHONB");
firstDockID = dataset.get(0);


Kevin
 
Thanks Kevin for your reply.
I tried to make those changes and it gives me an error anyway.
Since I only need 1 record, I'm going to look for a way to make the Json I receive have less structure for to be able to work it more easily

1724910250870.png
 
Back
Top