# Get pk from global typehead function that returns a string

**URL:** https://forum.servoy.com/t/get-pk-from-global-typehead-function-that-returns-a-string/18100
**Category:** Classic Servoy
**Created:** [August 5, 2014, 3:10pm UTC](https://forum.servoy.com/t/get-pk-from-global-typehead-function-that-returns-a-string/18100 "2014-08-05T15:10:48Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![deezzub](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@deezzub](https://forum.servoy.com/u/deezzub)
#### Post date: [August 5, 2014, 3:10pm UTC](https://forum.servoy.com/t/get-pk-from-global-typehead-function-that-returns-a-string/18100/1 "2014-08-05T15:10:48Z")

</div>

I have a valuelist with a global function for a typeahead field, that return the name of a customer, because I need the name to be stored in the dataprovider. After the customer is selected, I use a relation that is defined by customername to customername to update the other customer fields, like customerId etc., in my document. The problem is, if the customer name exists twice, the other fields could not be updated, if I select the other customer name in the typeahead field.

How can I get also the identifier for the customer record?

---

<div class="post-metadata">

### Author: ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)
#### Post date: [August 5, 2014, 4:24pm UTC](https://forum.servoy.com/t/get-pk-from-global-typehead-function-that-returns-a-string/18100/2 "2014-08-05T16:24:58Z")

</div>

Than you need a valuelist that shows names but returns some kind of ID. Than a relation back to you customers from ID to ID

---

<div class="post-metadata">

### Author: ![deezzub](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@deezzub](https://forum.servoy.com/u/deezzub)
#### Post date: [August 5, 2014, 4:27pm UTC](https://forum.servoy.com/t/get-pk-from-global-typehead-function-that-returns-a-string/18100/3 "2014-08-05T16:27:58Z")

</div>

> Harjo:  
> Than you need a valuelist that shows names but returns some kind of ID. Than a relation back to you customers from ID to ID

Hello Harjo, but I need the customer name in the dataprovider from the field where the typeahead valuelist method is attached. If I do your suggestion, then the id is returned to the dataprovider. That is what I want to avoid.

---

<div class="post-metadata">

### Author: ![deezzub](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@deezzub](https://forum.servoy.com/u/deezzub)
#### Post date: [August 6, 2014, 9:30am UTC](https://forum.servoy.com/t/get-pk-from-global-typehead-function-that-returns-a-string/18100/4 "2014-08-06T09:30:07Z")

</div>

I changed the customer name dataprovider to the customer id and return the customer id from the global valuelist method. In the valuelist I added a fallback valuelist from the table where I store the customer name and id. The valuelist is configured to show the customer in the field and return the customer id to the dataprovider.

This seems to work, except for the Servoy Framework find mode. If I want to search for a customer name, it does not find the desired records.

How can I bypass this?

---

<div class="post-metadata">

### Author: ![deezzub](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@deezzub](https://forum.servoy.com/u/deezzub)
#### Post date: [August 6, 2014, 12:48pm UTC](https://forum.servoy.com/t/get-pk-from-global-typehead-function-that-returns-a-string/18100/5 "2014-08-06T12:48:11Z")

</div>

The observed the problem in the Servoy Framework function svy\_sea\_search. I have 2 fields on my form: fld\_customer\_number and fld\_customer\_name which both have the dataprovider anmand attached, which the customer id number. The field fld\_customer\_name has the above valuelist with fallbackvaluelist attached, so it displays the customer name.

Field customer number with dataprovider anmand

[attachment=2]2014-08-06\_14\_23\_02-Servoy\_Design\_fld\_customer\_number.png[/attachment]

Field customer name with dataprovider anmand

[attachment=1]2014-08-06 14\_24\_19-Servoy\_Design\_fld\_customer\_name.png[/attachment]

Field customer name with no data, but in this field the search string is entered.

[attachment=0]2014-08-06\_14\_33\_45-Servoy\_debug\_fld\_customer\_name.png[/attachment]

 ![2014-08-06_14_33_45-Servoy_debug_fld_customer_name.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/8/8dbb5384db5eb2906e8fc0e00e3271068221e937.png)

 ![2014-08-06 14_24_19-Servoy_Design_fld_customer_name.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/d/dce2bb5bf24f5b1fb8411407a7198d2e3cf13c84.png)

 ![2014-08-06_14_23_02-Servoy_Design_fld_customer_number.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/c/c413f117aaf0c6f6b35732b222a1f0f72ae8cba1.png)

---

<div class="post-metadata">

### Author: ![deezzub](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@deezzub](https://forum.servoy.com/u/deezzub)
#### Post date: [August 6, 2014, 1:02pm UTC](https://forum.servoy.com/t/get-pk-from-global-typehead-function-that-returns-a-string/18100/6 "2014-08-06T13:02:45Z")

</div>

[attachment=2]2014-08-06\_14\_35\_33-Servoy\_debug\_fld\_customer\_name\_2.png[/attachment]

Field customer number with data, but in this field the search string is not entered.

[attachment=1]2014-08-06\_14\_36\_47-Servoy\_debug\_fld\_customer\_number.png[/attachment]

[attachment=0]2014-08-06\_14\_37\_50-Servoy\_debug\_fld\_customer\_number\_2.png[/attachment]

If I replace:

```auto
dataValue = forms[formNames[l]][dataProv];

```

with the search string:

```auto
dataValue = "Briese Schiffahrts GmbH & Co. KG MS \"Ostland\"";

```

the search works as aspected.

Is this a bug in Servoy or in Servoy Framework or do I need some better understandig how it works?

 ![2014-08-06_14_37_50-Servoy_debug_fld_customer_number_2.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/0/093fbede3169bb77e9e54cdf6bbe254d7b6b7125.png)

 ![2014-08-06_14_36_47-Servoy_debug_fld_customer_number.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/1X/d6757239128e47758b2ba5bcede0ae5460ac8ddb.png)

 ![2014-08-06_14_35_33-Servoy_debug_fld_customer_name_2.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/a/abfbe6a2a7067ea453a6bdf6ca99b960b50bd1ad.png)

---

<div class="post-metadata">

### Author: ![deezzub](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@deezzub](https://forum.servoy.com/u/deezzub)
#### Post date: [August 6, 2014, 4:05pm UTC](https://forum.servoy.com/t/get-pk-from-global-typehead-function-that-returns-a-string/18100/7 "2014-08-06T16:05:54Z")

</div>

> deezzub:  
> I changed the customer name dataprovider to the customer id and return the customer id from the global valuelist method. In the valuelist I added a fallback valuelist from the table where I store the customer name and id. The valuelist is configured to show the customer in the field and return the customer id to the dataprovider.
> 
> This seems to work, except for the Servoy Framework find mode. If I want to search for a customer name, it does not find the desired records.
> 
> How can I bypass this?

As a quick workaround, I created a patch that fixes it. There are of course some improvements to the code. ![;)]( "Wink") It is available at [SVYFRMWK-790: Cannot search in a field with attached valuelist (display / real value)](https://support.servoy.com/browse/SVYFRMWK-790)
