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