# Selecting only the first record from lookup

**URL:** <https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811>\
**Category:** Developers Forum\
**Created:** [October 13, 2015, 7:40am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811 "2015-10-13T07:40:46Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnikDatta](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@AnikDatta](https://www.dynamicsuser.net/u/AnikDatta)\
**Post date:** [October 13, 2015, 7:40am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/1 "2015-10-13T07:40:46Z")

</div>

Hello Everyone,

How could i select only the first record only from a lookup whereas cant access the other records but can view it?

Suppose having 4 lines on the lookup but able to select the first one only.

Thanks in Advance

---

<div class="post-metadata">

**Author:** ![archer89](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@archer89](https://www.dynamicsuser.net/u/archer89)\
**Post date:** [October 13, 2015, 11:10am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/2 "2015-10-13T11:10:06Z")

</div>

please describe in more detail what you need.

it’s not clear what you want.

---

<div class="post-metadata">

**Author:** ![subrata.bauri](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@subrata.bauri](https://www.dynamicsuser.net/u/subrata.bauri)\
**Post date:** [October 14, 2015, 8:08am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/3 "2015-10-14T08:08:41Z")

</div>

How do you sort the selected/filter records ?

Does User can able to change sorting method by selecting others key (if exist) ?

Try it:

Form/Page - OnQueryCloseForm() : Boolean

```auto
Record.SETCURRENTKEY(Field1, [Field2],...)

```

```auto
IF Record.FINDFIRST THEN BEGIN

```

```auto
   RecordVar2 :=Record.

```

```auto
   ......................

```

```auto
   ......................

```

```auto
END;

```

---

<div class="post-metadata">

**Author:** ![AnikDatta](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@AnikDatta](https://www.dynamicsuser.net/u/AnikDatta)\
**Post date:** [October 15, 2015, 5:22am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/4 "2015-10-15T05:22:29Z")

</div>

I am having a lookup field(table relation )in a subform. Now i have multiple lines there. I want that the user can only able to select the first line from that lookup not the other lines.

How could i do so??

Thanks all

---

<div class="post-metadata">

**Author:** ![gany408](https://avatars.discourse-cdn.com/v4/letter/g/9fc348/32.png) [@gany408](https://www.dynamicsuser.net/u/gany408)\
**Post date:** [October 15, 2015, 6:27am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/5 "2015-10-15T06:27:48Z")

</div>

Hi,

is there any line number for subForm? If exist, in that case it is possible…

---

<div class="post-metadata">

**Author:** ![AnikDatta](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@AnikDatta](https://www.dynamicsuser.net/u/AnikDatta)\
**Post date:** [October 15, 2015, 6:34am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/6 "2015-10-15T06:34:21Z")

</div>

yes, its having line no…So do i need to close the lookup from property & write it through code?

But how to catch only the first line ?

---

<div class="post-metadata">

**Author:** ![archer89](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@archer89](https://www.dynamicsuser.net/u/archer89)\
**Post date:** [October 15, 2015, 7:00am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/7 "2015-10-15T07:00:47Z")

</div>

to get only the first record redefine the filter criteria, so that you only get one line as lookup result, add e.g. line no. = 10000.

for writing lookup code follow

[https://msdn.microsoft.com/en-us/library/ee414204.aspx](https://msdn.microsoft.com/en-us/library/ee414204.aspx)

use rec.findfirst to get only the first record of a filtered result or use get function.

---

<div class="post-metadata">

**Author:** ![Mohamed\_Zayed](https://sea1.discourse-cdn.com/flex023/user_avatar/www.dynamicsuser.net/mohamed_zayed/32/7508_2.png) [@Mohamed\_Zayed](https://www.dynamicsuser.net/u/Mohamed_Zayed)\
**Post date:** [October 15, 2015, 1:05pm UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/8 "2015-10-15T13:05:03Z")

</div>

Hi,

you can set a filter on the table relation to select only the first line. Go to the table option/Table relation/set the filter between the source table and the destination table based on the line number.

🙂 Have fun coding

---

<div class="post-metadata">

**Author:** ![archer89](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@archer89](https://www.dynamicsuser.net/u/archer89)\
**Post date:** [November 2, 2015, 10:06pm UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/9 "2015-11-02T22:06:58Z")

</div>

hi,

is your question answered ?

---

<div class="post-metadata">

**Author:** ![AnikDatta](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@AnikDatta](https://www.dynamicsuser.net/u/AnikDatta)\
**Post date:** [November 3, 2015, 3:54am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/10 "2015-11-03T03:54:17Z")

</div>

yes, thank you all

---

<div class="post-metadata">

**Author:** ![archer89](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@archer89](https://www.dynamicsuser.net/u/archer89)\
**Post date:** [November 3, 2015, 7:12am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/11 "2015-11-03T07:12:16Z")

</div>

please verify the answers, which helped you to find a solution. thx.

---

<div class="post-metadata">

**Author:** ![AnikDatta](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@AnikDatta](https://www.dynamicsuser.net/u/AnikDatta)\
**Post date:** [November 9, 2015, 2:28am UTC](https://www.dynamicsuser.net/t/selecting-only-the-first-record-from-lookup/58811/12 "2015-11-09T02:28:40Z")

</div>

In on lookup trigger…

after setrange the by the common field the findfirst has worked for me.

IF PAGE.RUNMODAL(50087,pagename)=ACTION::LookupOK THEN

BEGIN

record.RESET;

record.SETRANGE(HpLedger.“Proposal No”,“Proposal No.”);

record.SETRANGE(HpLedger.“I.C No”,“Customer Nos.”);

record.SETRANgE(HpLedger.“Payment Status”,FALSE);

IF record.FINDFIRST THEN

“Line No”:=record.“Entry No”;

“Installment Amount”:= record.“Due Amount”;

“Due Date”:= record.“Due Date”;

END;
