# Populate Table widget with MS SQL data

**URL:** <https://community.ofelia.com/t/populate-table-widget-with-ms-sql-data/8917>\
**Category:** Q&A\
**Created:** [10 January 2018 13:20 UTC](https://community.ofelia.com/t/populate-table-widget-with-ms-sql-data/8917 "2018-01-10T13:20:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert.Wagemans\_1349](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@Robert.Wagemans\_1349](https://community.ofelia.com/u/Robert.Wagemans_1349)\
**Post date:** [10 January 2018 13:20 UTC](https://community.ofelia.com/t/populate-table-widget-with-ms-sql-data/8917/1 "2018-01-10T13:20:33Z")

</div>

Hi Everyone,

I have trouble displaying the result of a SQL connector (SQL server 2012) request to a simple Table widget.

\*This is the SQL request code \*:  
`String sqlStatement = "SELECT APPLICATION_NAME FROM dbo.DepartmentApp where APPLICATION_TYPE = 'STD' "; return sqlStatement;`

It returns the data as intended when I use “Evaluate”.

I then have a _Groovy script to format the resultset to JSON_ :

` import groovy.json.JsonBuilder; List<Object> dbResult = new ArrayList<Object>(); while(resultset.next()) { def jsonb = new JsonBuilder(); def line = jsonb { APPLICATION_NAME resultset.getString("APPLICATION_NAME") } dbResult.add(line); } return dbResult;`

I pass this value to the process variable named “listeApplicationsStandard”, a java.util.Collection object. I made sure it is “multiple” as well.

In the UI, I am able to retrieve the data via a REST API call :  
`../API/bpm/caseVariable/{{caseId}}/listeApplicationsStandard`

When I run the process, I can see it contains the values if I use a text field with {{listeApplicationsStandard.value}}. It displays the following data :  
`[{APPLICATION_NAME=Olympic Opérations C&I Standard}, {APPLICATION_NAME=Kynox Opérations C&I Standard}] `

When I try to show the data contained in {{listeApplicationsStandard}} in a text field, it shows :  
`{"case_id":"168001","name":"listeApplicationsStandard","description":"","type":"java.util.Collection", "value":"[{APPLICATION_NAME=Olympic Opérations C&I Standard}, {APPLICATION_NAME=Kynox Opérations C&I Standard}]"} `

However, I have been trying for days to display its content in a Table, following the different help topics I could find on the Bonitasoft forum, notably [http://community.ofelia.com/node/21600#node-21610](http://community.ofelia.com/node/21600#node-21610).

I was not able to get a single string displayed in the Table. I use `applicationsStandard.value` in the “content” field of the table and made sure to check the “fx” function for the content to be dynamic. The column key is set to` APPLICATION_NAME`

I feel the format of the JSON Groovy script is where the incident is, but I haven’t been able to solve this yet. I think there should be some quotes (" ", " ") in the values returned by the JSON builder. Does anyone see where my mistake is ? Any help will be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Robert.Wagemans\_1349](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@Robert.Wagemans\_1349](https://community.ofelia.com/u/Robert.Wagemans_1349)\
**Post date:** [12 January 2018 07:20 UTC](https://community.ofelia.com/t/populate-table-widget-with-ms-sql-data/8917/2 "2018-01-12T07:20:16Z")

</div>

For anyone searching about this strange behaviour, I solved it by replacing :

`../API/bpm/caseVariable/{{caseId}}/listeApplicationsStandard `  
by

`../API/bpm/activityVariable/{{taskId}}/listeApplicationsStandard`

All of a sudden, the variable contained the data formatted correctly in Json with the Value keys and Values correctly displayed in the table. It appears the caseVariable call is defective and/or limited.

Another way to tackle it if you have no choice is to use the “JsonOutput” method in your resulset Json builder :

`while(resultset.next()) { def jsonb = new JsonBuilder() def line = jsonb { APPLICATION_NAME(resultset.getString("APPLICATION_NAME")) } def jsono = JsonOutput.toJson(line) dbResult.add(jsono) }`

But even with a perfectly Json formatted string, this method would not carry all the data when using “caseVariable”.

---

<div class="post-metadata">

**Author:** ![romualdo.s.rs](https://avatars.discourse-cdn.com/v4/letter/r/9fc348/32.png) [@romualdo.s.rs](https://community.ofelia.com/u/romualdo.s.rs)\
**Post date:** [11 January 2018 17:15 UTC](https://community.ofelia.com/t/populate-table-widget-with-ms-sql-data/8917/3 "2018-01-11T17:15:46Z")

</div>

Why do not you try moving to a BDM variable? This makes it much easier to display the contents of the UI Designer in a table.
