Arrays and Value Lists

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Arrays and Value Lists

Postby Morley » Tue Nov 09, 2004 3:32 am

I have a tabpanel using a relationship that includes a global on the left side (pk) of the relationship. Works fine. The tabpanel displays records with a tick box or check box. I want to build a dynamic value list that includes just the items ticked.

Much to my surprise the same relationship that controls the tabpanel does not work when used in a value list. Using the unmodified relationship the combobox presents a drop down of blank, nada, nothing. I suspect, but am not sure, the problem is the global on the left hand side of the relationship.

Anyone have recommendations on how to achieve the functionality I want? One possibility might be to assemble an array of the ticked items and use that to generate the value list. Not sure how arrays can be used in VLs. Other options?

I'm groping around in the dark.
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby Morley » Tue Nov 09, 2004 6:36 pm

I've adapted some sample code Maarten posted in Forum Topic 618 on how to use arrays in value lists. In Maarten's code he uses a SQL query to gather up all the records of a table.

In my approach I'm pre-loading the form with just the records I want. Then I'm creating my arrays. However the result is I'm ending up with a single line value list showing "Fruit, Cereals" instead of:

Fruit
Cereals

Also when I use the value list it's not returning anything, is leaving the combobox field empty.

Any ideas?

Code: Select all
var max = controller.getMaxRecordIndex();
var names = ''; // iniate variable
var id = ''; // iniate variable

for ( var i = 0 ; i < max ; i++ )
{
   var current = controller.getSelectedIndex();
   names = names + name + ','; // concatenate field contents separated by a comma
   id = id + tableid + ','; // concatenate record id's separated by a comma
   controller.setSelectedIndex(current + 1);
}
controller.setSelectedIndex(1);

var length = names.length;
names = utils.stringIndexReplace(names, length - 1, 2, ''); // trim the final comma
var length = id.length;
id = utils.stringIndexReplace(id, length - 1, 2, ''); // trim the final comma

var nameArray = new Array(names);
var idArray = new Array(id);

application.setValueListItems('valuelistname', nameArray , idArray );
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby Morley » Tue Nov 09, 2004 7:16 pm

I've solved one problem and vastly simplified the method.
Code: Select all
var nameArray = databaseManager.getFoundSetDataProviderAsArray(foundset,'name');
var idArray = databaseManager.getFoundSetDataProviderAsArray(foundset, 'recordid')

application.setValueListItems('valuelistname', nameArray , idArray );

I'm now setting the array properly and indeed the combobox now displays:
Fruit
Cereals
on separate lines.

However it's returning nothing, nada.

The Value List is set for "Custom Values" as Maarten noted. My intuition suggests something more is required to instruct the VL to return the second column of the array.

Can anyone spot what's missing?
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby bcusick » Tue Nov 09, 2004 7:30 pm

Make sure you UNCHECK the "editable" checkbox on the combobox field.

Then it will work.

Bob
bcusick
 
Posts: 1255
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Postby Morley » Tue Nov 09, 2004 8:01 pm

It does indeed!! Remarkable. Appreciated.
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 39 guests