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 -

import java.sql.ResultSetMetaData;
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.

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:

your code/log

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

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

Multiple markers at this line
- 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’

I’ve been trying this as well…and I think it can’t be done even though it should be possible.

I’ve created a bug report with a full example of what I’m trying to do as I need it to work as well,

regards

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

First to the select statement I got an answer regarding the bug…here:

https://bonita.atlassian.net/browse/BBPMC-478

I’ll work this one out later but it does answer the question.

Now regarding your latest post - Thu, 03/30/2017 - 11:46

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)

Been there, seen it, done it… :slight_smile:

There is a learning curve and if you’re doing this for a commercial organization I would definitely talk to sales here: http://www.bonitasoft.com/contact-us

Make sure you mention that you’re doing an evaluation for potential purchase…

Once you have decided to go with whom-ever definitely send someone on a virtual course, here:
http://www.bonitasoft.com/products/services/training

Oh by the way i don’t work for them, this is just a semi-template that I use when people ask these questions…

OK down to specifics:

  • 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.

Funny - I also use OSTicket…

This isn’t so much about can Bonitasoft do it as much as can the target system accept it. Bonitasoft can do it by definition of the language it is written in, Java, so yes Bonitasoft can talk to…using connectors etc…

Can OSTicket interface - just searching the Googl-Web I found this, a couple of years old, so will require researching OSTicket for more updates…

http://osticket.com/forum/discussion/75804/documentation-on-how-to-sync-users-with-other-system-via-rest-json

Limited.

  • Connect to other resources with connectors

Yes, but again depends on the capability of “other” systems

  • Allow other resources to connect and trigger processes

Yes, through REST, and triggering resources is as simple as sending a Message (we do this a lot) or a Signal (not so much)

Starting a process can be seen here http://documentation.bonitasoft.com/?page=bpm-api#toc22, scroll down to Create a Case

  • See if we can build a custom front end wrapper around the processes and present them like a service catalog

I’ve done this via an Application front end. Basically built a page with the links/pictures of the “Service” that starts the delivery process. Each delivery process is of course different based on requirements of the “Service”.

Hardware requires inventory, purchasing, blah, blah, blah…

Whereas User Provisioning and security profiles are done differently.

Applications are not as clean as they could be but they do work and allow a fair amount of flexibility.

  • Be flexible enough to allow us to develop it without unreasonable limitation

I would suggest it is, but as with OSTicket you may be restricted by the backend. It’s then where you have to determine the limitation and how to get round it.

So far it does everything I want it to do.

However I would definately contact Bonitasoft and because you’re doing a formal evaluation you should be able to ask them anything you like and get a real answer.

BUT, yes the inevitable but. Like all new technologies, if you’re not used to it there will be a learning curve, it takes time, but once you know it, it becomes easier…

Hope that helps
regards

Seán

PS: For full disclosure, I do not work for Bonitasoft and have been to their offices in Grenoble once, nice bunch of people. These are only my opinions and others may have their own. I do get frustrated sometimes and think I should shorten Bonitasoft to BS but I eventually sort out my issue and it works.

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