Hi everyone,
I have a simple process with a mysql connector that should fetch data from a db and save it to a process variable. On the UI side, I want to display the process variable into a select widget.
I have a simple script that return a string in JSON format
def patientList = '[{"id": 1, "label": "Patient Name"}]';
which is assigned to a process variable “testVariable” of type text.
Then, on the UI Form I created an external API variable pointing at “…/API/bpm/caseVariable/{{task.caseId}}/testVariable”, and assigned the property “Available values” of the select widget to it. However, the select widget appears empty without any option to be selected. What am I doing wrong?
Furthermore, I noticed that the return type of the Groovy script can’t be changed and it’s always java.lang.String. Could that create some problems in my setting?
A .bos of the process can be found here: https://www.dropbox.com/s/gdfesfrwk4jmto9/p_A-1.0.bos?dl=0
Thanks in advance.
Best
EDIT
I overcome my initial problems.
Now I’m able to load data from my external database and parse it into a java String variable, which then I get with an external API call in the UI. I have now a final problem: I end up with one option for each character in the string.
I know it must be something really stupid and I also saw a similar post in the forum about this problem but I’m not able to find it again!
Thanks in advance.
Best
1 Like
Hello
Let me try to understand the Problem.
your json variable has 2 key:value pairs but at any time you can display only one set of key:value .
You want to display both Id and label together side by side .
if this is what you want , then
take a container. Add a text widget. Clear out the default sample text. Add the Json variable name patientList to the container collection property.
use {{$item.id}} and {{$item.label}} to display values.
regards
Hi Dibyajit.
Not exactly. I want the select widget to display the label only and I need the id as returned key.
Best
In this case, Usually Dropdown widget works the Best. You have the option to attach the J SON to the available value section. You have displayed key and returned Key sections to map your specific keys from J SON.
Checklist, checkbox, Radio buttons can also handle J SON values.
I dont think Textbox can handle J SON.
Just to display, you can use the Above suggestion.
Take a container, inside the container, drag a text widget. Clear out the sample french text.
Map the value as {{$item.label}} .Make sure the collection has J SON variable name set.
You can write custom JavaScript to return the id .
This is how i mostly manipulate my values.
regards
Thanks for your answer.
Yes, I am already using a dropdown widget (called select widget in the Bonita form editor).
If I map the values using {{$item.label}} I get an empty list with the epxression
{{ properties.placeholder | uiTranslate }}
as placeholder.
The process variable I defined in the Bonita BPM hat java.lang.String as type. Might this be the problem?
Best
Dont use {{$item.label}} with dropdown widget.
For Drop Down , you can map the J SON variable name directly to the available values section in the Drop Down and mention label as the Displayed key.
{{$item.label}} can be used in case of container.
regards
I tried that as well but I end up with the widget having an option for each single character in my string (but all options are displayed empty).
Best
Indeed, it was the type of the variable (java.lang.String) causing the problem.
In the UI Form I created a second variable as a javascript expression that parses the string from the API call (the first variable) and return a JSON string. Using this second variable yields the wanted result.
Maybe it will be better to have the variable from the API call already as JSON but I find it faster to use javascript to parse a JSON-correct string on the UI side.
Thanks everyone for the help.
Best