# Using TYPE\_AHEAD with global method valuelist

**URL:** <https://forum.servoy.com/t/using-type-ahead-with-global-method-valuelist/16363>\
**Category:** Classic Servoy\
**Created:** [August 17, 2012, 8:27pm UTC](https://forum.servoy.com/t/using-type-ahead-with-global-method-valuelist/16363 "2012-08-17T20:27:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwaite](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@mwaite](https://forum.servoy.com/u/mwaite)\
**Post date:** [August 17, 2012, 8:27pm UTC](https://forum.servoy.com/t/using-type-ahead-with-global-method-valuelist/16363/1 "2012-08-17T20:27:57Z")

</div>

I am attempting to use a global method as the valuelist for a TYPE\_AHEAD element on a form, but am having some trouble with it; currently, I have Servoy version 6.1

I connected to the example\_data server and created a form using the “orders” table for the data source, selecting all fields in the form creation dialog. After creating the form, I changed the displayType for the employeeid element on the form to TYPE\_AHEAD. Next, I opened the valueList dialog for this element, selected the Global method option, and clicked the dotted button to the right of the text box to create a new global method.

Next, I clicked the Scope button, which displayed a default name for the global method: getDataSetForValueList. I left the default name unchanged, and clicked the Create button. Finally, I clicked OK. The text box to the right of the Global method radio button was then filled in with the following text:

scopes.globals.getDataSetForValueList(displayValue,realValue,record,valueListName,findMode)

When I examined the sample code created by default for this method (by clicking the folder icon), I saw that it queried the employees table, selecting the employeeid and the concatenated first and last name. I saved the valueList that I created, calling it “employeesList”, and made sure that the TYPE\_AHEAD element on my new “orders” form showed employeesList for its valueList property and that the dataProvider property for the element was set to “employeeid”.

I ran the solution in the Web Client, checking to make sure that the employee first and last name were changing as I navigated between orders. The problem was that when I attempted to type within the TYPE\_AHEAD text box, I would see the list of employees appear for several seconds, but then the employee name that was originally selected for that record would overwrite what I was typing.

Am I misusing the global method valuelist in some way? Keep in mind that I did not change the sample code that Servoy automatically generated for the global method.

Thanks in advance to anyone who can help me.

---

<div class="post-metadata">

**Author:** ![achiary](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@achiary](https://forum.servoy.com/u/achiary)\
**Post date:** [August 21, 2012, 9:38pm UTC](https://forum.servoy.com/t/using-type-ahead-with-global-method-valuelist/16363/2 "2012-08-21T21:38:00Z")

</div>

Can you please post the code you are running ?

---

<div class="post-metadata">

**Author:** ![mwaite](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@mwaite](https://forum.servoy.com/u/mwaite)\
**Post date:** [August 22, 2012, 7:06pm UTC](https://forum.servoy.com/t/using-type-ahead-with-global-method-valuelist/16363/3 "2012-08-22T19:06:31Z")

</div>

Here is the code, which is the sample code generated by Servoy when you first create a global method for a valuelist (I have not altered this code in any way):

function getDataSetForValueList(displayValue, realValue, record, valueListName, findMode) {

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  
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;

}
