Focal Point
[Closed]Dynamic query with field names listed in listbox

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/4227029286

June 29, 2016, 08:58 AM
Ramya
[Closed]Dynamic query with field names listed in listbox
Hi All,

I gone through many post and I didn't get exactly what I wanted.

I have a list box with list of values which are actually fields from different tables.

I need to write a dynamic SQL query with those fields selected in the list box.

If user has selected values from the listbox(it might be fields from single table or multiple tables). Say if the selected fields are from the single table its going to be a simple select query without any joins.

I am trying this to avoid unnecessary joins to tune the performance.

Can someone suggest me with ideas.

Thanks,
Ramya
Webfocus 8105

This message has been edited. Last edited by: Ramya,
June 29, 2016, 11:32 AM
Neelima
Hey .

use following blog:-

http://pravinsinghwebfocus.blo...-column-control.html

thanks
Neelima


WebFocus 8104,8204
Excel/PDF/HTML/HTMLTABLE/XML/ALPHA/GIF file/GRAPH/Active technologies
June 30, 2016, 01:53 AM
Ramya
Hi Neelima,

Yes the blog gives me the approach what exactly is required.

But there the number of fields are limited. So he has used so many number of variables.

In my case I have 10 tables with 100 fields in each, So I don't think this approach is going to help me out.

Thanks,
Ramya


WebFocus 7702
HTML
June 30, 2016, 10:46 AM
Kevin W
A report user is going to scroll a dropdown to pick from a list of one thousand possible options? That seems excessive and not user friendly. just my two cents. Smiler


WebFOCUS 7.7.05 (Someday 8)
Windows 7, All Outputs
In Focus since 1983.
June 30, 2016, 12:58 PM
Kofi
quote:
seems excessive and not user friendly.

Me agree much so. Perhaps a UX / UI designer is you need?

Kofi


Client Server 8.1.05: Apache; Tomcat;Windows Server 2012
Reporting Server 8.1.05; Oracle; MS SQL; Windows Server 2012
June 30, 2016, 01:00 PM
Kofi
Or meebe you be needing guided adhoc?


Client Server 8.1.05: Apache; Tomcat;Windows Server 2012
Reporting Server 8.1.05; Oracle; MS SQL; Windows Server 2012
July 01, 2016, 08:26 AM
Ramya
quote:
meebe you be needing guided adhoc

Hi Kevin,

User is not going to select all the 100 fields at once. Each user may want to select a minimum number of fields according to what is required for them.

one option I am thinking is,We can write a query with all the 10 tables and only the select list can differ according to what the user is selecting.

So now a question is,If a user is selecting fields from only one table, then its going to take a long time for the user to get the result as I have used all the 10 tables in the query.

I am just looking out for some options.

Thanks,
Ramya
WebFocus 8105,HTML,Javascript
July 01, 2016, 09:22 AM
Squatch
Ramya,

I do not have a complete solution for you, but I have an idea that might help.

A listbox is an HTML select tag. A select tag has a "text" property and a "value" property. Text is what the user sees in the listbox. Value is not seen by the user and can be the same as the text property or it can be different.

You could put the field names in the text property, and the name of the tables they belong to could go in the value property. So when a user selects a field name you can check the value property to get the table name.

After collecting all the field and table names, you can delete any duplicate table names and then write your dynamic query.

Example code:

-HTMLFORM BEGIN
<script type="text/javascript">
function build_listbox() {
	var fields_and_tables = {
	  "records" : [
	     { "fieldname" : "customer_id", "tablename" : "customer_table" },
	     { "fieldname" : "customer_name", "tablename" : "customer_table" },
	     { "fieldname" : "product_id", "tablename" : "product_table" },
	     { "fieldname" : "price", "tablename" : "product_table" },
	     { "fieldname" : "in_stock", "tablename" : "product_table" },
	     { "fieldname" : "shipping_address", "tablename" : "customer_table" },
	     { "fieldname" : "special_instructions", "tablename" : "notes_table" }
	  ]
	};

	var listbox = document.getElementById("listbox1");

	for (i = 0; i < fields_and_tables.records.length; i++) {
		var option = document.createElement("option");
		option.text = fields_and_tables.records[i].fieldname;
		option.value = fields_and_tables.records[i].tablename;
		listbox.add(option);
	}
}

function show() {
  var x = document.getElementById("listbox1");
  alert('text = "' + x.options[x.selectedIndex].text + '", value = "' + x.options[x.selectedIndex].value + '"');
}
</script>
<body onload="build_listbox();show()">
<select id="listbox1" onchange="show()"></select>
</body>
-HTMLFORM END



App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
July 01, 2016, 09:26 AM
Ramya
quote:
all the field and table names, you can delete any duplicate table names and then write your dynamic query.


Hi Squatch,

That's the great idea. Will give a try and let you know on how it goes.

Thanks,
Ramya
WebFocus 8105,HTML,Javascript
July 21, 2016, 06:00 AM
Ramya
quote:
select tag has a "text" property and a "value" property. Text is what the user sees in the listbox. Value is not seen by the user and can be the same as the text property or it can be different.You could put the field names in the text property, and the name of the tables they belong to could go in the value property. So when a user selects a field name you can check the value property to get the table name.After collecting all the field and table names, you can delete any duplicate table names and then write your dynamic query.



Hi Squatch,


Since the final listbox from which I am pulling values to report is dynamic, I am unable to predefine the fields with 'display text' and 'value'. If its static, your suggestion works perfectly.

Any ideas on how to handle this in dynamic listbox?

Thanks
Ramya
Webfocus 8105, HTML, Javascript
July 21, 2016, 08:51 AM
Squatch
quote:

Any ideas on how to handle this in dynamic listbox?

Yes.

You need to create a WebFOCUS report that will return field names and table names. Your data source might be able to do this, but if it cannot do this, you could create a new data source with all the field names and table names.

The WebFOCUS report needs to return this data in XML format. I will use the CAR file as an example. Pretend MODEL is field names and COUNTRY is table names:

TABLE FILE IBISAMP/CAR
PRINT 
     CAR.CARREC.MODEL
     CAR.ORIGIN.COUNTRY
ON TABLE PCHOLD FORMAT XML
END

When you have created the XML report that returns field names and table names, create your list box in App Studio. Then follow these steps:

1. In the "Requests & Data sources" panel, New --> External Request --> WebFOCUS Procedure. Select the WebFOCUS XML report you created.

2. Click on your list box, then open the "Settings" panel. Dynamic --> Explicit (Requests panel). Select the WebFOCUS XML report from the "Request" drop down control. For "Value from" select the field that contains your table names (COUNTRY in my example above). For "Display from" select the field that contains your field names (MODEL in my example above). Select a sort order of "Ascending".

Then you will need a way to look at all the user selected fields and get all the unique table names. You should be able to do that with JavaScript.

This message has been edited. Last edited by: Squatch,


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
July 21, 2016, 09:53 AM
Ramya
Squatch,

I got it. But we don't populate the listbox from external procedure. Its just 3 listboxes in the left and user selects the value from all 3 and sends it to the final listbox.

Same way you suggested, I have tried giving two different values one in display text and other in value text in source listboxes in the left.

When I pass it to the right final listbox, I can still pass either text or value. I am just trying some luck using hidden objects where I will pass both text and value and manipulate it when taking it to report.

Kindly suggest if this work around will do

Thanks,
Ramya
WebFocus 8105, HTML, Javascript
July 21, 2016, 10:50 AM
Squatch
When you wrote earlier that the final listbox was dynamic, I thought you meant WebFOCUS dynamic.

If you have two different values for display text and value text in source listboxes, you should be able to copy them both to the final listbox.

Like this:

var listbox = document.getElementById("final_listbox_on_right");

// Pass both display text and value text to final listbox on right
var option = document.createElement("option");
option.text = (display text from source listbox on left side);
option.value = (value text from source listbox on left side);
listbox.add(option);

The "text" is what is between the OPTION opening and closing tags. But it looks like WebFOCUS listboxes add a "displaytext" attribute as well:

<OPTION value=Red displaytext="Apple">Apple</OPTION>



App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
July 22, 2016, 02:33 AM
Ramya
quote:
listbox.add(option);


Thanks a lot SquatchSmiler

That got worked. I got to know a simple new thing today. When we add an item to listbox, both text and value attribute gets added.

Thanks,
Ramya
WebFocus 8105,HTML,Javascript