How to load default values in a task form from h2 database?

Hi to all,

I would like to ask the following:

In my html task form, a drop-down list of default values is loaded from an html code in Eclipse.
Could anyone guide me a bit please on how can these values be loaded from an h2 database table instead of the html code ?
I would like to add/remove those default values from a relative table in h2 database.

Thanks a lot in advance,
Steve

Hey @steftriant,

There are some options here.

  1. Load the drop down values from a process variable as specified here . You could fill out the process variable with data using a service task before your user task.
  2. Load values from an external rest endpoint that could be connected to your database using the embedded task form and some javascript/jquery/ajax. See this forum post for examples and some github links (refer to answer b).

Regards,

1 Like

Hey @patozgg, thanks a lot for your feedback and sorry for my delay.

I took a first look at your suggested options here and I’ve been trying to work with your 1st option.
Please let me ask you some points here:

My bpmn diagram is the following:

As you suggested, I added a Service Task before my User Task.

My html code for the User Task form is the following:

<div class="col-md-6">                                																																						
      					<div class="form-group">                              																																					
       						<label class="control-label" for="category">Select Category:</label>
       						<div class="controls">
        						<input list="category" name="categories" style="width:250px;" ng-model="Category" />   																											
								<select id="category"
										cam-variable-name="PRODUCT_CATEGORY"
        								cam-variable-type="String"
        								cam-choices="AVAILABLE_PRODUCT_CATEGORIES">
									<option value="001">Desktop</option>
									<option value="002">Laptop</option>
									<option value="003">Tablet</option>
								</select> 
       						</div>
      					</div>
     				</div>

But having read the relative chapter from Docs here Selects | docs.camunda.org I see that the values of user’s options are pre-configured, like my html code above.
This isn’t what I want as I explained. What I want to achieve is to load the values of user’s options from an h2 table.
Could you please guide me a bit on the way of filling out the process variable with data from the h2 ?
Where must I write the marked script below ?

Thanks a lot in advance,
Steve

Hey @steftriant,

Sorry for the late response. Been away with some customers.

Based on the process model that was attached in the last message. My recommendation would be the following.

  1. The Service Task should be using a Java Delegate. Such Java Delegate should be doing something like this.
Map<String, String> productTypes = new HashMap<String, String>();
   
productTypes.put("001", "Notebook");
productTypes.put("002", "Server");
productTypes.put("003", "Workstation");
execution.setVariable("AVAILABLE_PRODUCT_TYPES",  Spin.JSON(productTypes));

Note that the Java Delegate example in here does not really explain what is the customerData object. So it makes it a little confusing as to what needs to get serialized and how to do it.

The idea with this Java Delegate is that from here it is possible to fetch data from an h2 database. Personally I am not an h2 SQL query expert, but using some Java code it is possible to fetch data from almost anywhere. From a quick Google search I found this tutorial. Of course, some code logic to parse the data would be necessary.

  1. Next the User Task Embedded form should have the following.
 <select cam-variable-name="PRODUCT_TYPE"
         cam-variable-type="String"
         cam-choices="AVAILABLE_PRODUCT_TYPES">
 </select>

Note that I did not hard code any of the values, but these were dynamically read using the cam directive.

Hope this helps!

Regards,