How to populate a Table Widget in Bonita 7.4.2 from a REST API Call?


I am a newbie at using Bonita for the automation of a customer onboarding process and wish to display the customers from REST API call which is powered by MySQL Server.

Currently, my approach is to bind the content of the table to a variable that contains JavaScript code to make the REST API call and return the response.

When I try to execute the form with this approach, it gives me the following error:
Uncaught DOMException: Failed to construct 'WebSocket': The URL 'wsockets/254/4v399h8_/websocket' is invalid.

I am unable to understand why this error is showing up.

The code snippet for retrieving the result from API Call is as follows:
var xhr = new XMLHttpRequest();'GET', 'http://xxxx.xx:xxxx/los/v1/fetch_retailers_list', true);
xhr.setRequestHeader('Authorization', '');
xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");
var response = null;
if (xhr.status == 200){
response = JSON.parse(xhr.responseText);
return response;

Any guidance on this issue is greatly appreciated as I have been struggling to get this completed.
There is another way to get the output in a tabular widget - using a DB Connector. I know how to configure a connector (MySSQL, for instance) but how to process the response from it and display it in the table widget.

Thanks in advance.

1 answer

This one is the BEST answer!

I think you are confusing two things, notably because of the error:

Uncaught DOMException: Failed to construct 'WebSocket': The URL 'wsockets/254/4v399h8_/websocket' is invalid.

I think you are trying to execute this in the UI Preview? If so then this will not work as there is no background service for the REST call to talk to. This is indicated by the WebSocket error. The web server is not available.

This will not happen when you are executing the process, as in RUN the process.

Yes, it's a pain, but it's the way it works. Every change when you want to see real working change needs to be executed through the RUN command.

That's why when using test data in a variable it works. It's localized to the UI.

Regarding the DB Connector, just take the response output and change it to JSON format, there are many ways to do this on the Googl-Web, put it in a process variable and then access this with a REST Context call. Again this will only work through a RUN execution and not from UI Preview.


PS: While this may not be the complete answer you're hoping for, it does indicate a possible solution, please mark as resolved.


Submitted by megha on Mon, 03/27/2017 - 06:37

Thank you for the prompt reply and clarifying the confusion regarding the API rest call and WebSocket exception. I just want to know if this approach will work fine (binding the content of the table with the response from the REST API as a Javascript Expression).

Also, can I get few resource links on how to configure a DB Connector and writing Java/Groovy Script to take the response and display/use it in UI.

Thank you!

Submitted by Sean McP on Mon, 03/27/2017 - 21:40

The approach should work fine yes, in fact we do this type of AJAX call all the time, works very well.

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.