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

  1. * SELECT *
  2. * FROM tableName
  3. * ORDER BY columnName ASC;
  4.  
  5. *
  • ->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)...

  1. /**
  2.  '
  3.  ' Comments for your code
  4.  ' This code includes how to log to the tomcat log under
  5.  ' installDir\workspace\tomcat\logs
  6. '
  7.   */
  8. import java.text.SimpleDateFormat;
  9. import org.bonitasoft.engine.api.ProcessRuntimeAPI;
  10. import java.util.logging.Logger;
  11.  
  12. int dI = 0;
  13. boolean debug = true; // change to false when not debugging.
  14.  
  15. ProcessRuntimeAPI processRuntimeAPI = apiAccessor.getProcessAPI();
  16. String processName = processRuntimeAPI.getProcessInstance(processInstanceId).getName();
  17.  
  18. //set the name of the routine
  19. String thisTrace = " "+processName+ " readDatabase: "
  20.  
  21. Logger logger= Logger.getLogger("org.bonitasoft");
  22. if(debug){dI++; logger.severe(dI+thisTrace+"Trace Start");}
  23. //TODO - Code goes in here
  24.  
  25. ArrayList<String> listofconfigs = new ArrayList<String>(); // new list
  26. listofconfigs.add("Select from the following list:"); // initialize with first line
  27.  
  28. int noofrows = 0;
  29. while(resultset.next()){ //loop on results
  30. String S = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(resultset.getDate("uploaddate"));
  31. listofconfigs.add(S + " " + resultset.getString("theColumn You Want"));
  32. noofrows++;
  33. }
  34. if(noofrows.equals(0)){ //for when there are no records
  35. listofconfigs.remove(0);
  36. listofconfigs.add("There are no stored Configs");
  37. }
  38.  
  39. if(debug){dI++; logger.severe(dI+thisTrace+"Trace End");}
  40.  
  41. 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