Dropdown list with data from external DB in Bonita BPM Community

1
0
-1

I would like to configure dropdown list widget in form that list data from external DB. As I am using Bonita BPM Community it is not possible to use connectors in forms. As I understand the only option to retrieve data in this case is to write a groovy script that will query data from DB for this widget. Is it correct? Or are there any other options?

2 answers

1
0
-1
This one is the BEST answer!

Ah the noobie wants to learn,

Go forth grasshopper and search the world...experiment...it's a wonderful thing, or when all else fails go on a course.... :) If you don't know about grasshopper you've missed out, though I'm not sure he was ever called that in the TV series.

Sorry, it's late, and EuroVision will be won tomorrow by the Aussies', what is the world coming too?

Right to get the selected item,

First create a Pool variable of type String, called it selectedItem (or whatever).

On the application form, click the selection list, click on the Detail->Data Tab and in Output Operation

on the LHS select the variable selectedItem and on the RHS select the form field field_whateveritscalledontheform.

That's it, done, when the user selects the item from the list the selected item will appear in the pool variable selectedItem.

Hope that helps, regards

Comments

Submitted by shpak.serhiy on Fri, 05/22/2015 - 22:13

It's that simple ) Thank you!

1
0
-1

No, not in community, well I haven't sen any other way of doing it.

The way to do it is create a script connector to get the data and save it to a list variable, then use the list variable as the data to the drop down list.

I actually prefer this as it keeps the manipulation of data away from the presentation of data. And you can see the step on the diagram... :)

Having hidden scripts on a form may be useful but is a real PITA when trying to debug something.

regards

Comments

Submitted by shpak.serhiy on Fri, 05/22/2015 - 12:23

Hi, Sean. Thank you for your answer. I have just began study Java. Could you please give me a hint which classes shall be used in this script?

Submitted by Sean McP on Fri, 05/22/2015 - 14:40

create your process as follows:

  • Start->Script Step->Human Task Step->End

  • in the pool add a data variable myList as java Object List

  • Add a database connector to the Script Step and complete the details, depends on your Database of course.

  • Here is one for Postgres:

  • give it a name->Next

  • add the appropriate driver->Next
  • complete the access Info->Next
  • complete your select statement

*     SELECT *
*     FROM tableName
*     ORDER BY columnName ASC;

*  
  • ->Next
  • select SCRIPTING MODE->Next
  • in Output Operations:
  • LHS - select your List Variable myList
  • RHS click the pencil to open the editor

  • Once open - Change the Return Type to List and add a name

  • add the following code (modify to suit your own requirements)...

/**
 '
 '   Comments for your code
 '   This code includes how to log to the tomcat log under
 '   installDir\workspace\tomcat\logs
'
  */

 import java.text.SimpleDateFormat;
 import org.bonitasoft.engine.api.ProcessRuntimeAPI;
 import java.util.logging.Logger;
 
 int dI = 0;
 boolean debug = true;  // change to false when not debugging.
 
 ProcessRuntimeAPI processRuntimeAPI = apiAccessor.getProcessAPI();
 String processName = processRuntimeAPI.getProcessInstance(processInstanceId).getName();
 
 //set the name of the routine
 String thisTrace = " "+processName+ " readDatabase: "
 
 Logger logger= Logger.getLogger("org.bonitasoft");
 if(debug){dI++; logger.severe(dI+thisTrace+"Trace Start");}
 //TODO - Code goes in here
 
 ArrayList<String> listofconfigs = new ArrayList<String>(); // new list
 listofconfigs.add("Select from the following list:");              // initialize with first line
 
 int noofrows = 0;
 while(resultset.next()){ //loop on results
         String S = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(resultset.getDate("uploaddate"));
         listofconfigs.add(S + " " + resultset.getString("theColumn You Want"));
         noofrows++;
 }
 if(noofrows.equals(0)){ //for when there are no records
         listofconfigs.remove(0);
         listofconfigs.add("There are no stored Configs");
 }
 
 if(debug){dI++; logger.severe(dI+thisTrace+"Trace End");}

 return listofconfigs;
  • Click OK
  • Click Finish

  • and run...

you can then check the Bonita*.log for anything that goes wrong. That's if you write to it of course.

When I started Bonita a year ago I knew nothing of JAVA except it's an island off Indonesia. There are many great resources for learning JAVA not least stackoverflow.com to ask questions, but make sure you search first.

You'll get there,

regards

Submitted by shpak.serhiy on Fri, 05/22/2015 - 20:23

Hi, Sean. Thank you for the detailed guide. It works! And I immediately have faced with another issue. How to put a selected value from drop down menu into new variable in order to use it further in the process? I tried to play around with variables. What I could do - just to put the whole list from List variable into another List variable. Feel stupid)

Thank you for advising stackoverflow.com. There are tons of educational materials on Java. I tried some courses on Lynda.com, but I don't like it. Maybe could you advice some book or resource on this topic?

Thank you!

Notifications