Populate select widget from a process variable
Hi All,
I've tried pretty much every combination of searches and gone through the tutorials before I got here. My groovy scripting is limited but I'm getting there and seen lots of examples of how to populate an array, map, list. collection.... or whatever the method at the time calls it.
I basically have a localhost mssql DB called BonitaSoft, a table called users and 3 columns Firstname (varchar 50), Surname (varchar 50), Title (varchar 8) and ID (Int). I've then populated it with 3 test users.
What I want to do is populate a select widget on a form with the Firstname values from this DB. I have tried lots of combinations but the current setup is that I have a process variable called hashMap with a Data type of Java Object and the class set to java.util.HashMap.
I then setup a pool level connection which connects to the local db, does a select * from users and then enters scripting mode. From there I have the process variable 'hashMap' take the value of 'resultset' and the 'resultset' script is -
HashMap<String,String> hm= new HashMap<String,String>();
resultset.beforeFirst();
while (resultset.next()) {
String key = resultset.getString('firstname');
String value = resultset.getString('firstname');
hm.put(key,value);
}
return hm;
In a new form that I attached to a human task I've added a variable called 'myListAlt' with a value of '../API/bpm/caseVariable/{{task.caseId}}/hashMap' and added a select widget which uses this form variable in the value * and *available values properties.
The best I have managed is for the dropdown to show a single value per row i.e. C, h, r, i, s... and this was done by adding myListAlt.value to the value * and *available values properties in one of the combinations.
Any help appreciated
Thanks
You need to translate your ResultSet from the Select to JSON
Regarding MySQL to JSON
Use this post and search for getJSONFromResultSet answered Nov 7 '16 at 22:08 by Yanir Calisar
You can create your own Groovy Script (Develop->Manage Groovy Scripts) and then call this whenever required with the MySQL resultset and it will return the proper JSON for you.
regards
Seán
PS: As this reply offers an answer your question, and if you like it, please Mark UP and/or as Resolved.
Comments
Hi,
I've copied the script as is (found in the link) into the script section of the connection properties and left this pushing values to the process variable 'HashMap' (I had already created) but I see this error in the script window
- Groovy:expecting '}', found ':' @ line 16,
column 64.
- Groovy:unexpected token: : @ line 16,
column 64.
I have to assume I'm adding the script to the wrong place or not changing something I need to.
I've also seen the section for storing scripts too but don't know how to call them yet.
Finally, I've not changed anything else so the form widget still points at the form variable called 'myListAlt' with a value of '../API/bpm/caseVariable/{{task.caseId}}/hashMap'
As I am just at the stage where I am scoping potential systems I havent been allocated development resource. I was just trying to see if it will do things like -
- Push and pull values from a DB i.e. add a ticket into something like OSTicket as part of a process flow and pull the values as required.
- Connect to other resources with connectors
- Allow other resorces to connect and trigger processes
- See if we can build a custom front end wrapper around the processes and present them like a service catalog
- Be flexible enough to allow us to develop it without unreasonable limitation
Once I've fully scoped it out I should hopefully be able to acquire someone more skilled than myself. Sort of stuck between a rock and a hard place at the moment where I need to build it to see if we can build on it (if that makes sense)
Have you submitted bugs before and if so in your opinion how quick are they normally dealt with? In other words is it a thriving community? I'm coming from a paid for service where we are limited by the providor in the terms of development and non essential fixes are bi-annual.
Thanks
I've downloaded your .bos file and it looks like I was certainly on the right track. The only difference being that my lack of knowledge didn't allow me to see another way and I was stuck thinking it was me misundertanding.
I've approached sales to see the lay of the land regarding subscription, training, etc. I'd hate to dismiss it on the basis of cost when I don't know what the cost is. This will probably factor into the decision for the final choice.
Difficulty lies that I've been given little insight into where these processes will end up; and only told that it needs to be scaleable, connectable and for the time being able to connect to an open source ticket system and calendar. I'm approaching this from the point of view of being a service manager where I'm trying to accomodate what I believe we will connect to and what the company have asked for over the last 5 years. The multitude of connectors, custom widgets, ability to build front-ends, etc are why I see the potential here. I'm already used to bending processes into a system that wasn't intended for the job so I see little problem with putting processes into a process oriented system with dedicated resource.
Good to see OSticket is currently compatible and I'm just waiting for a VM to be set up so I can put a proper test configuration in place (rather than wamp on my machine).
I don't anticipate the backend of OSticket being a problem either as the same resources available for BS will be available for OSTicket enhancements.
Whilst I'm very willing to learn I'm also trying to stand back and run the team as a manager rather than an engineer. For far too long i've been both and need to take a back seat so that I can run a team rather than a system - this doesn't help at the moment though as I need to put in place a concept and can't do so without some knowledge - plus it's never bad to know what you'r guys are upto.
Have a good weekend!
Chris
Comments
A Tip on displaying CODE/LOGS correctly in Posts:
Do not use the Supplied Buttons above, for some reason they refuse to work correctly, and despite bringing it to Bonitasofts attention, it's low priority.
To Show Code/Logs correctly use
< code >
your code/log
< /code >
removing the spaces to allow the showing of code/logs correctly as here:
You should still be able to edit your post to ensure the correct formatting of the code to help us understand it easier.
Thanks and regards
Seán
Done thanks