Comobox fill via global method, Servoy 5.2

Hello,

Put text field on the form, changed displayType to COMBOBOX, attached valuelist vl_displaytext_value_pairs;
In valuelist chosen Global method radio, attached method fill_vl_displaytext_value_pairs that collects values from the DB;
pseudo of global method:

function fill_vl_displaytext_value_pairs() {
    application.output('fill_vl_displaytext_value_pairs');	
    application.setValueListItems( 'vl_displaytext_value_pairs', null );
    var sql = "SELECT CONCAT(prompt_values,' ',prompt_description), prompt_values FROM prompt WHERE prompt_field = 'test'"; 	
    var ds = databaseManager.getDataSetByQuery( globals.DATA_SERVER,sql,null,-1 );	
  return ds;
}

BUT combobox is filled couple of times with array of values from datasource?! Why?
I see in logs that fill method is invoked couple of times on form load/show? How to control this?
Anyway, when I set default value for the comobofield -it is filled properly (only 1 datasource array is there)?! But I don’t have default value in all cases

How to correctly fill combobox via global method?

Regards

P.S.
Auto generated sample is below, but not need that logic. Is the custom logic above correct?

/**
 
* Called when the valuelist needs data, it has 3 modes.
* real and display params both null: return the whole list
* only display is specified, called by a typeahead, return a filtered list
* only real value is specified, called when the list doesnt contain the real value for the give record value, this will insert this value into the existing list
*
 * @param {String} displayValue The value of a lookupfield that a user types
* @param {Object} realValue The real value for a lookupfield where a display value should be get for 
* @param {JSRecord} record The current record for the valuelist. (This is the FindRecord in find mode, which is like JSRecord has all the columns/dataproviders, but doesn't have its methods) 
* @param {String} valueListName The valuelist name that triggers the method. 
*
 * @returns {JSDataSet} A dataset with 1 or 2 columns display[,real]
 * 
* @properties={typeid:24,uuid:"8EFF270F-156B-405D-A291-550F75EA14BF"}
*/

function getDataSetForValueList(displayValue, realValue, record, valueListName) {
	
	if (displayValue == null && realValue == null) 
 	 {		
		// TODO think about caching this result. can be called often!		
		// return the complete list		
	  return databaseManager.getDataSetByQuery("example_data", "select firstname || ' ' || lastname, employeeid from employees", null, 100);	
      	 } 
	 else if (displayValue != null) 
	   {	
		// TYPE_AHEAD filter call, return a filtered list		
		var args = [displayValue + "%", displayValue + "%"]		
	     return databaseManager.getDataSetByQuery("example_data", "select firstname || ' ' || lastname, employeeid from employees where firstname like ? or lastname like ?", args, 100);	
	   } 
	 else if (realValue != null) 
	   {		
		// TODO think about caching this result. can be called often!		
		// real object not found in the current list, return 1 row with display,realvalue that will be added to the current list		
		// dont return a complete list in this mode because that will be added to the list that is already there		
		args = [realValue];		
 	     return databaseManager.getDataSetByQuery("example_data", "select firstname || ' ' || lastname, employeeid from employees where employeeid = ?", args, 1);	
	   } 
	
   return null;
}

P.P.S.
Found
http://omar4.dotnet35.hostbasket.com/se … neral.aspx
but not able to use it because don’t have permission to maintain the DB

first of, why are you calling this:

application.setValueListItems( ‘vl_displaytext_value_pairs’, null );

in the global method of the valuelist itself? That shouldn’t be done, the return value of the global method will fill that for you

Besides that you REALLY need to follow the sample code, there are a few different api contracts that need to be followed.

Thanks for response jcompagner,

Haven’t been able to fill the valulist without duplicates via global method and trying now with
http://omar4.dotnet35.hostbasket.com/se … neral.aspx
Works well in general, but another issue turned up:
Need to assign a name to the valuelist that matches exactly the (array of) values in valuelist_name column, but created valuelist is not visible from different module? Why? Anyway, it’s prevented to create same valuelist (with same name) in 2 different modules. Don’t want to fill the table twice as a work-over

How to assign valuelist from other module to COMBOBOX?

Regards

you need to add the module that has the valuelist as a module of that other module/solution.

Please add the above sample with the explanation of the arguments to the Wiki pages, because the Wiki pages do not mention anything about using global methods (not even in the 6.0 Wiki)

i can find for example this one:

http://wiki.servoy.com/display/public/D … thodValues

also here you have some more info (as a solutionmodel example)

http://wiki.servoy.com/display/public/D … obalMethod

But if you have some nice idea’s where you expect to find it and what should be improved please tell us

jcompagner:
But if you have some nice idea’s where you expect to find it and what should be improved please tell us

I was looking (and expecting it) here: http://wiki.servoy.com/display/public/DOCS/ValueList