# Set Up Lookup Filter from Javascript

**URL:** <https://forum.kintone.dev/t/set-up-lookup-filter-from-javascript/104>\
**Category:** General\
**Created:** [April 23, 2019, 4:04am UTC](https://forum.kintone.dev/t/set-up-lookup-filter-from-javascript/104 "2019-04-23T04:04:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [April 23, 2019, 4:04am UTC](https://forum.kintone.dev/t/set-up-lookup-filter-from-javascript/104/1 "2019-04-23T04:04:24Z")

</div>

Dear Developers,

As title said, when I on a create page with a Lookup Field, I want to set that lookup Filter manually with javascript instead of setting it up from kintone app settings.

So when user want to lookup, the lookup already display the filtered record as desired, the filter itself should be able to change, dynamically based on a condition that I wrote on javascript.

Is there any way to do that? If so, please let me know.

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [April 23, 2019, 11:05pm UTC](https://forum.kintone.dev/t/set-up-lookup-filter-from-javascript/104/2 "2019-04-23T23:05:36Z")

</div>

Hello Afief!

&nbsp;

So what I understand, basically you want the Lookup Field to do its job automatically based on the value that you write on a javascript upon creating a record or editing a record.

&nbsp;

Then the script can be something like this:

```
(function() {

"use strict";

kintone.events.on(['app.record.create.show','app.record.edit.show'], function(event) {

var record = event.record;

record['Lookupfield']['value'] = 'XXX'; // Lookup Field Value

record['Lookupfield']['lookup'] = true; // When this is true, it automatically looks up upon the value is entered

return event;

});

})();

```

&nbsp;

I hope this helps.

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [September 23, 2019, 11:29pm UTC](https://forum.kintone.dev/t/set-up-lookup-filter-from-javascript/104/3 "2019-09-23T23:29:44Z")

</div>

Hello, you solution Yuzo Arai, works if the lookup field key match is unique. But if its a lookup for a field that it has not unique values it wont work. Is it possible to make the lookup by the record number internally, but display the name on the lookup? So it always make the lookup?

Thank you

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [September 26, 2019, 12:01am UTC](https://forum.kintone.dev/t/set-up-lookup-filter-from-javascript/104/4 "2019-09-26T00:01:49Z")

</div>

If the record number is available internally as a key, it might work.

However, you cannot edit the value of the look up field with a different value  
after you get the value of the lookup field with the record number.

Like your situation, if the lookup field does not have unique values,  
you can set the name to a different field by looking up  
with the record number and copying to another field.  
If you do not want to show the lookup field that includes the record number,  
you can hide the lookup field.
