# How to get a Record ID from a Lookup field?

**URL:** <https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613>\
**Category:** General\
**Tags:** lookup-field, record-id, record-number-field\
**Created:** [October 2, 2022, 7:56pm UTC](https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613 "2022-10-02T19:56:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![unudeveloper](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/unudeveloper/32/257_2.png) [@unudeveloper](https://forum.kintone.dev/u/unudeveloper)\
**Post date:** [October 2, 2022, 7:56pm UTC](https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613/1 "2022-10-02T19:56:04Z")

</div>

Hello, everyone.  
I want to get the Record ID from a Lookup field.

As you know, we can get the App ID of the Datasource app of the specified Lookup field with the [Get Lookup Target](https://kintone.dev/en/docs/kintone/js-api/get-data/get-record/#get-lookup-target) JavaScript API.

```javascript
kintone.app.getLookupTargetAppId(fieldCode)

```

But I do not know how to get the Record ID of the Datasource app of the Lookup field.

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/chris/32/44_2.png) [@Chris](https://forum.kintone.dev/u/Chris)\
**Post date:** [October 4, 2022, 5:29pm UTC](https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613/2 "2022-10-04T17:29:58Z")

</div>

Hello @unudeveloper

You just need to:

1. Obtain the key field of a Lookup field from the event object
2. Include it in the REST API(GET) query to obtain the target record.

You can directly get the ID from the event object if you’ve set a record number as the key field.

> **[Get Records](https://kintone.dev/en/docs/kintone/rest-api/records/get-records/)**
>
> Retrieves details of multiple records from an App by specifying the App ID and a query string.

---

<div class="post-metadata">

**Author:** ![unudeveloper](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/unudeveloper/32/257_2.png) [@unudeveloper](https://forum.kintone.dev/u/unudeveloper)\
**Post date:** [October 4, 2022, 6:07pm UTC](https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613/3 "2022-10-04T18:07:39Z")

</div>

Hello @Chris ,

Thanks for your help.

> You can directly get the ID from the event object if you've set a record number as the key field.

Yes, I can.  
However, I have set the "title" field (not the Record number) as the [Lookup field's key field](https://get.kintone.help/k/en/id/040547.html#lookup_set_lookup_30).

_Let me ask a question._

### Question 1: Getting the second record

How do I ensure I get the correct record if there are two records with the same title (in the title field)?  
What if the query results in the first record, but I want the second record?

How can I solve this?

_Also, I have another question._

### Question 2: Why am I unable to get the Record Number directly?

By hovering over the Lookup field from the "Lookup Picker" window, I can see that text is hyperlinked to the record, which includes the Record Number (as shown below).

 ![Screenshot of a Lookup Picker window and the record 233 is being hovered over by the mouse](https://canada1.discourse-cdn.com/flex035/uploads/kintone/original/1X/3711a8201347ea6f402312dd6346e15b76ddc47f.png)

But then why am I unable to get the Record Number directly with something like this?

```javascript
kintone.app.record.get().record["lookup"].xxx

```

⚡ Related API Docs:

- [Get Record Details - `kintone.app.record.get()`](https://kintone.dev/en/docs/kintone/js-api/get-data/get-record/#get-record-details) API Doc
- [Get Lookup Target - `kintone.app.getLookupTargetAppId()`](https://kintone.dev/en/docs/kintone/js-api/get-data/get-record/#get-lookup-target) API Doc

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/chris/32/44_2.png) [@Chris](https://forum.kintone.dev/u/Chris)\
**Post date:** [October 4, 2022, 6:47pm UTC](https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613/5 "2022-10-04T18:47:55Z")

</div>

Hello @unudeveloper

You will need to include the data obtained thru the Lookup field as a key to specify which record.

And about the 2nd question, I’m not quite sure what the problem is, but I assume your question is why the record number differs from the URL in the lookup field. Please correct me if I’m wrong.

“233” is the record number of that record in the app.  
The record number you see in the URL is the record number of the record that the lookup field references.  
In other words, they are completely different records.

---

<div class="post-metadata">

**Author:** ![unudeveloper](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/unudeveloper/32/257_2.png) [@unudeveloper](https://forum.kintone.dev/u/unudeveloper)\
**Post date:** [October 4, 2022, 10:09pm UTC](https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613/7 "2022-10-04T22:09:45Z")

</div>

Dear @Chris ,

### Question 2 Response

> [@Chris](#):
>
> And about the 2nd question, I'm not quite sure what the problem is, but I assume your question is why the record number differs from the URL in the lookup field. Please correct me if I'm wrong.

Sorry, I was missing a sentence in the second question.

I can get the Record ID from the "Lookup Picker" window.

But then why am I unable to get the Record Number directly with something like this?

```javascript
kintone.app.record.get().record["lookup"].xxx

```

### Question 1 Response

> [@Chris](#):
>
> You will need to include the data obtained thru the Lookup field as a key to specify which record.

Sorry, I do not quite understand.

Could you please elaborate?

Thank you.

---

<div class="post-metadata">

**Author:** ![Sean\_Tcbn](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/sean_tcbn/32/68_2.png) [@Sean\_Tcbn](https://forum.kintone.dev/u/Sean_Tcbn)\
**Post date:** [October 6, 2022, 9:35pm UTC](https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613/8 "2022-10-06T21:35:03Z")

</div>

Hi @unudeveloper,

Let’s say; for example, there is a field that can be duplicated; on my test app, I used the lookup field to lookup a product name and also a text field that displays a size.  
When trying to look up, the same product name is displayed.

It would be impractical to determine which records to look up based solely on the duplicable fields.

Therefore, if the field is duplicable, the “size” (information obtained in the lookup) can also be included in the query when retrieving records to identify the record.

I hope this explains what Chris mentioned previously.

---

<div class="post-metadata">

**Author:** ![unudeveloper](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/unudeveloper/32/257_2.png) [@unudeveloper](https://forum.kintone.dev/u/unudeveloper)\
**Post date:** [October 6, 2022, 9:57pm UTC](https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613/9 "2022-10-06T21:57:12Z")

</div>

Hi @Sean_Tcbn  
Thank you . I understand what you mean.  
But I just wanted to get the record id like this.  
`kintone.app.record.get().record["lookup"].xxx`  
If it is possible, could please explain about why I can’t get the record id like getting the App Id.  
Regards.

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/chris/32/44_2.png) [@Chris](https://forum.kintone.dev/u/Chris)\
**Post date:** [October 12, 2022, 6:46pm UTC](https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613/10 "2022-10-12T18:46:23Z")

</div>

Hello @unudeveloper  
This is impossible because this API does not obtain the whole data of the other record grabbed by a lookup field. It only grabs data that is specified in the lookup field settings.  
You can see this by looking at the response of the API:

```javascript
var record = kintone.app.record.get();
console.log(record);

```

And there’s no API like App ID that precisely does it as of now.

I hope this answers your question.

---

<div class="post-metadata">

**Author:** ![unudeveloper](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/unudeveloper/32/257_2.png) [@unudeveloper](https://forum.kintone.dev/u/unudeveloper)\
**Post date:** [October 12, 2022, 7:16pm UTC](https://forum.kintone.dev/t/how-to-get-a-record-id-from-a-lookup-field/613/11 "2022-10-12T19:16:35Z")

</div>

Hi @Chris  
Thanks for your response.  
I also tried to get the record id using ` kintone.app.record.get()` but unfortunately it returned  
`"Lookup": { "type": "SINGLE_LINE_TEXT", "value": "Document Title" }`.  
It is same as Text field.

```javascript
"Text": {
    "type": "SINGLE_LINE_TEXT",
    "value": "sample"
  },

```

It will be great , developers can get record id using ` kintone.app.record.get()` .  
I want your opinion.  
Best Regards.
