Dynamic valuelists

just started using servoy and I am having an issue with valuelists. what i’m trying to do is have one valuelist that is setup to show all values from the ‘clientname’ column in the ‘clients’ table. upon selecting a clientname from the combobox, another valuelist will populate with all the projects relating to that client. the project names come from the ‘projects’ table and i’ve created a relationship between clients and projects based on the ‘clientnum’ column in clients and ‘projectclient’ in the projects table; relationship is called ‘clients_to_projects’ I have done quite a bit of searching on the forums and still have been unsuccessful in accomplishing what I want to do. Any help will be greatly appreciated, I will provide you guys with any information you need.

thanks.

Hi IndySkys,

Which table are you trying to trigger this valuelist from ?

You have mentioned clients and projects but not where you are choosing the clientname.

In order to trigger this conditional valuelist you have to have the key locally to base the relationship on.

This will probably NOT be the relationship that you have already said that you have between the two tables !

Please let us know a little more about the structure that you have

Cheers
Harry

Firstly, thank you for the reply, Harry.

my tables are built with the following columns:

clients
clientnum (PK)
clientname

projects
projectnum (PK)
projectclient (FK)
projectname
projectcontract

im trying to populate the second, or projects, valuelist based upon selecting a client from the first valuelist which gets its values from the ‘clients’ table. the project names which i want to populate the second valuelist with will be getting it’s data/values from the ‘projects’ table, projectname column and like i had mentioned earlier, i have a relationship between the two tables based on clientnum in clients and projectclient in projects. i see that you say my relationship that i have formed is not correct and you’re probably right because im new to this. if you require more information please let me know because this is all i can think of to post at the moment.

thanks.

Hello IndySkys,

I think the following link can be helpfull for you,

http://www.servoymagazine.com/home/2006 … l#download

This example will explain you how to use dynamic value list constructed on relation.

:)

DomTom

As well as looking at the excellent tutorial you may want to consider the following:

If you are generating your client list from the client table on a form based on the client table then you need to be storing the ‘clientnum’ value from the first valuelist inside a global field.

Then you can create a relationship to the project table based on this global as in: ‘clients::clientnum_global → projects::projectclient’

Then you can base your valuelist on this relationship

Cheers
Harry

Or you can use SQL queries to generate your value lists.

var query = "Select clientname from clients";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null,-1);
application.setValueListItems( 'valueListClients',dataset);

This will generate the value list for you first global field (gClientName). Assign an onDataChange method to this, something like this:

var query = "Select projectname from projects where projectclient = '" +gClientName+ "'";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null,-1);
application.setValueListItems( 'valueListProjects',dataset);

This will dynamically generate your second value list.

If you are generating your client list from the client table on a form based on the client table then you need to be storing the ‘clientnum’ value from the first valuelist inside a global field.

Then you can create a relationship to the project table based on this global as in: ‘clients::clientnum_global → projects::projectclient’

I am unsure of how to do this… I understand the principle but am unable to figure out how to do so within Servoy. Like I said… im a n00b to this and just started using it at the request of my boss. Any help on how to create that global field would be greatly appreciated.

Hi IndySkys,

I think that ultimately this comes down to our old friend the Manual and the help files.

Open the online help and search for ‘global’ or ‘relation’ and you will get a host of references

You can create global variables through either the globals node in the Method Editor (Under Application) or through the Define Dataproviders dialogue.

The global variables are resident in Servoy only and do not exist in your backend database

You can also define a relation using this global through the same Method Editor node or through Tool → Relations from the menu bar

Also, have a look through the Sample CRM solution provided with Servoy

It is crammed with illustrative structure, forms, methods examples for you to use to learn with or simply just plagiarise :x

You may also want to give an outline of what your skill level is in certain areas other than Servoy as this is a key reason why I did not mention using a SQL query as an option earlier !

That will give people an understanding of perhaps how to frame replies

Hope this helps
Harry

Harry, outside of Servoy the only skill I have that would probably pertain to this would be SQL. I will take your advice and read through the manuals and find what im looking for and also check out the samples that you had mentioned… I’d like to thank each and every one of you for taking the time to help me out in trying to get this thing working! Thanks!

If you get into real difficulty then post back

It would be a quick process to rack up a simple solution to demonstrate this

Cheers
Harry

thanks guys! i figured out how to create global fields and relations based off of globals and now everything works great! thanks to you all for your help!