Populate form with mysql data
Hi,
I created an editable grid and successfully saved data into table. But I am not able to populate form with this data. I have three data fields on form : name, email, partner
At pool level java.util.List type variable javalistfromdb
At connector level in output operation definition :
"javalistfromdb" takes value of
import groovy.sql.Sql; import java.sql.Driver; def String str; def host = "localhost:3306"; def user = "root"; def pass = "root"; def schema = "test"; def result = [:]; def sql = BonitaSql.newInstance("jdbc:mysql://$host/$schema","$user","$pass", new com.mysql.jdbc.Driver());
def query="";
query="select name
,email
, partner_name
from data";
sql.eachRow (query, { row-> result.put(row.name, row.email, row.partner_name) })
sql.close()
I have no idea how to bind each fild with the data from sql
Regards Manoj
Hi.
Rather than creating your own connector, you can use the MySQL connector that already is inside Bonita BPM. In the output of the connector your will obtain a List of List that contains the data you read in your database.
If you want to read each data in this List of List you can do this :
row.get(0); // name
row.get(1); // email
row.get(2); // partner
}
If you have multiple row, you can't populate a single field with all the value all at once. I don't know what excactly you want to do so I can't help more.
Hi,
I created new task (step 2) with form
On each field on form (i.e. name, email, partner) under Data tab->initial value->script I have written the code
when I run the form it opens the default input form which contains fields(email, name, partner and "submit" button) which is blank.
I changed the button label for my form from "submit1" to "submit form" but still the form is created as default for three fields.
I even moved the data fields created at pool level to step2 but same result.
any idea what can be the issue?
Thanks Manoj
Comments
Thanks for reply,
Ok, I used MySql connector and in Query/Batch Script window I wrote sql:
select name, email, partner_name from data where name='myname'
then in output window (Graphical mode) I selected "javalistfromdb"(which was created at pool level of java.util.List type), is it ok?
Then I created a form at this step1 ( which contains above Mysql connector also) now, I want fill the values in three fields in form. How to set value we get from above sql to form fields? where to write code?
Please help Thanks Manoj
Yes, this is ok.
I recommand to create the form on a new task after the task that contains the connector.
I think that the result of your query is only one row. To fill each field you need to add this code in the Data tab "Initial Value" :
else if (javalistfromdb.size() <1) return null;
else return javalistfromdb.get(0).get(X);
// Where X is 0 for name, 1 for email and 2 for partner