Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » SQL Options query returning just one field

SQL Options query returning just one field

Lars Larsen
Lars Larsen
Reply

Hi

If you eg. have an itemtype field of type checkbox list. And define the options to be of type SQL and the SQL statement only returns one field, the list is not rendered in the backend:

<Sql query="SELECT ItemTypeDefinitionsSystemName AS Name FROM ItemTypeDefinitions ORDER BY ItemTypeDefinitionsSystemName" nameField="Name" valueField="Name" accessDb="" />

The list is rendered if you make this work-around:

<Sql query="SELECT 1 AS DummyField, ItemTypeDefinitionsSystemName AS Name FROM ItemTypeDefinitions ORDER BY ItemTypeDefinitionsSystemName" nameField="Name" valueField="Name" accessDb="" />

 

Running DW v9.1.4


Replies

 
Nicolai Pedersen
Reply

Hi Lars

Is this changed behavior? You need a key and a value for the radio buttons. You can just select the same field twice if it is the same. If you use 1 as dummyfield, you get 1 saved as the value when you save the item.

BR Nicolai

 
Lars Larsen
Lars Larsen
Reply

Hi Nicolai

Don't know if this is changed behavior. In my first example I do have just one field for both key and value, as you suggest. But that doesn't work! 

 
Nicolai Pedersen
Reply

Could you explain what "does not work" means?

 
Lars Larsen
Lars Larsen
Reply

Hi Nicolai

Sure. If you have this query which returns just one column and sets value and label to the column "Name":

<Sql query="SELECT ItemTypeDefinitionsSystemName AS Name FROM ItemTypeDefinitions ORDER BY ItemTypeDefinitionsSystemName" nameField="Name" valueField="Name" accessDb="" />

 then the options in the checkboxlist is not rendered if you create an instance of the itemtype. But if you add just one more column to the query then the options is rendered. Eg.:

<Sql query="SELECT 1, ItemTypeDefinitionsSystemName AS Name FROM ItemTypeDefinitions ORDER BY ItemTypeDefinitionsSystemName" nameField="Name" valueField="Name" accessDb="" />

It's weird, but I can reproduce this behavior with the two queries above.

 
Nicolai Pedersen
Reply

Do it like this: SELECT ItemTypeDefinitionsSystemName AS Value, ItemTypeDefinitionsSystemName AS Name.

BR Nicolai

 
Lars Larsen
Lars Larsen
Reply

Hi Nicolai

Yeah that will work, because there are more than one column in the query. But if you don't know that the query needs to have at least two columns in order to render the options, you can spend a lot of time (which I did) with trial and error in order to figure that out. I would consider this as an error.

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Maybe, and it will not work if you do not know how to write a SQL statement... :-).

A select box has a key/value, so should the SQL - it is a developer feature. I will add it to TFS though.

Have a nice weekend, Nicolai

Votes for this answer: 1

 

You must be logged in to post in the forum