Can't display value to SELECT widget on UI designer

1
0
-1

Hi, I tried to display some data from mySQL (using connector) to SELECT widget on UI designer. I test the database and successfully connected. I use n columns x n columns on the graphical mode (because I have two columns, 1 consist of ID and the other consist of Name). Here is the return from the test function :

ArrayList:[[1, Adam], [2, Beck], [3, Charlie]]

I already create a process variable named jsonAgain (with data type list -> List) and I already declared the variable on UI designer using external API and here is the URL :

../API/bpm/activityVariable/{{taskId}}/jsonAgain

I tried to use the SELECT widget and can't get the data from the available value. Can someone point what is wrong with this? Thanks so much :)

1 answer

1
+1
-1

Hi,

Your array in the available values of the Select widget should contain JavaScript objects instead of arrays:

 [ {id:1, name: "Adam"}, { id: 2, name: "Beck" }, {id:3, name:"Charlie"}]

To retrieve the data in a proper format in your page or form, I recommend storing your database query result into a Business Data Object. BDM can then be queried using the Bonita HTTP API in your UID page.

For example, you can create a BusinessObject DatabaseUser in your project BDM, with a name attribute. All BusinessObjects have persistenceId attribute, so it is not necessary to add one. Then, in your process, you can create a business variable of type DatabaseUser which is multiple. In the connector output operation (script mode) of the database connector, you can create a list of DatabaseUser based on the resultset output:

 
def users = []
while (resultset.next()) {
    def name = resultset.getString(1) // Depends on your SELECT query
    def user = databaseUserDAO.newInstance()
   user.name = name users.add(user)
}
return users
 

Then, in a UID page, you can use an External API variable to retrieve instances of DatabaseUser:

../API/bdm/businessData/DatabaseUser?q=find&p=0&c=99

This variable can be used as available values of the Select widget, using persistenceId as returned key and name as displayed key.

UPDATE: Here is the example project on the bonitasoft-community Github organization

HTH
Romain

Comments

Submitted by UndergradLads on Thu, 02/09/2023 - 04:31

Welp thanks for the answer! I reproduce your given steps :

1. Create a BusinessObject named DatabaseUser with attribute name.

2. Create a Business Variable of type DatabaseUser and set it into multiple

3. Create a Database Connector and set it to Script mode, and add the script you gave me

4. In UI designer, create a new variable to retrieve the instance of DatabaseUser

And I still can't display it when I test it. Is it probably something with the step number 3? (is it still using takes values from or should I change it to use a java method?) or is it because I put the connector on the Connector In?

And one more question, actually I want to get the data from API (JSON typed) and I want it straight into the UId (so I want to store the JSON data on the BDM and call it to the UId but I don't know would it work and how to do it)

Hope you'll reply soon :)

Thanks :)

Submitted by romain.bioteau on Fri, 02/10/2023 - 09:20

And one more question, actually I want to get the data from API (JSON typed) and I want it straight into the UId (so I want to store the JSON data on the BDM and call it to the UId but I don't know would it work and how to do it)

If there already is a HTTP endpoint for your data why not consuming it directly in an External API variable in the UID ?

Otherwise it would be the same logic, duplicate the data in the BDM using the REST connector instead of the database connector.

Submitted by UndergradLads on Fri, 02/10/2023 - 10:08

I still can't find how to return 2 different data's from the REST Connector Output expression (I only can store 1 data to the BDM and I got 3 for example)

Here is my code (yours actually Mr. Romain :) ) :

import groovy.json.JsonSlurper

def jsonSlurper = new JsonSlurper()
def body = jsonSlurper.parseText(bodyAsString)
return body._embedded.element //Note : This is to simplify the nested Json that I have. My data is in this "element" dir. Its variable are name and id (I need this ID cuz I dunno why OpenProject API sometimes generate random ID)

I'm aware that if I use return, I will only get 1 reply (even thought I loop it on array) , so I tried to put it on the business variable so that I can parse it on the UId. (That's what I thought)

and thats why I tried using Database for my alternative in the first place :(

Maybe I miss-step something? Thanks in advance for answering! :)

Submitted by romain.bioteau on Sat, 02/11/2023 - 15:11

You can reuse the bodyAsMap or bodyAsString connector output in several connector output operations for the same request.

Each operation can store a different business variable.

Submitted by UndergradLads on Mon, 02/13/2023 - 04:38

Hi again, thanks for answering :) I actually need my connector to be as dynamic as possible so I didn't have to re-edit my connector if my API got different count on the array.

Now I only can create output expression using bodyAsString only for one array. For bodyAsMap, I haven't try it and I can't find any examples for it.

Sorry I am new to Groovy and Java code

Thanks in advance for answering :)

Notifications