web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

How to check Duplicate Records using AL code?

(0) ShareShare
ReportReport
Posted on by 2,086

Hi All,

I need to check the duplicate records from the table and if I found duplicate address in the records then I need to move that record in the Custom Log table,

So, can anyone tell me How Can I check the duplicate records in the AL?

Thank You.

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,696 Moderator on at
    RE: How to check Duplicate Records using AL code?

    Hi,

    Can you export all the data using config. package? or use Edit in Excel feature of the page.

    Thanks.

  • Inkey Solutions Profile Picture
    2,086 on at
    RE: How to check Duplicate Records using AL code?

    Hi, Nitin Verma ,

    I need to do it dynamically, so can you please provide any suggestion that is used by AL code? Thanks.

  • Suggested answer
    Nitin Verma Profile Picture
    21,696 Moderator on at
    RE: How to check Duplicate Records using AL code?

    There is no way to do it dynamically in standard system. You need to customize it.

  • Inkey Solutions Profile Picture
    2,086 on at
    RE: How to check Duplicate Records using AL code?

    Hi, Nitin Verma ,

    I tried this code, does this works?

    pastedimage1676354839946v1.png

  • Suggested answer
    Nitin Verma Profile Picture
    21,696 Moderator on at
    RE: How to check Duplicate Records using AL code?

    PS - ALWAYS SEND CODE IN TXT FORMAT

    You can try to put logic like this.

    If you want me to edit it. share you code in txt format.

    Thanks.

  • Inkey Solutions Profile Picture
    2,086 on at
    RE: How to check Duplicate Records using AL code?

    Nitin Verma :

    Here it is,

    [EventSubscriber(ObjectType::Table, Database::"Fixed Asset", 'OnAfterModifyEvent', '', false, false)]

    begin

    if rec.Address1 <> '' then begin

               Rec.SetRange(Address1, Rec.Address1);

               if Rec.FindSet() then begin

                   Message('Duplicate Found');

               end else begin

                   Message('Not Found');

               end;

        end;

    end;

  • Suggested answer
    Nitin Verma Profile Picture
    21,696 Moderator on at
    RE: How to check Duplicate Records using AL code?

    You can try this

       [EventSubscriber(ObjectType::Table, Database::"Fixed Asset", 'OnAfterModifyEvent', '', false, false)]

       local procedure OnAfterModifyEventFA(var Rec: Record "Fixed Asset")

       var

           FixedAsset: Record "Fixed Asset";

       begin

           if rec.Address1 <> '' then begin

               FixedAsset.Reset();

               FixedAsset.setfilter(Address1, Rec.Address1);

               if FixedAsset.Count > 1 then

                   Message('Duplicate Found')

               else

                   Message('Not Found');

           end;

       end;

  • Inkey Solutions Profile Picture
    2,086 on at
    RE: How to check Duplicate Records using AL code?

    Thank You Nitin Verma , this is works for me.

    Can you tell us that How we can prevent the Insertion of duplicate records? [we want that do not allow the insert duplicate records.]

  • Suggested answer
    Nitin Verma Profile Picture
    21,696 Moderator on at
    RE: How to check Duplicate Records using AL code?

    You need to write the code OnbeforeInsert event and put the error if any duplicate found or ignore the record by putting Error('')

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,401

#2
Sumit Singh Profile Picture

Sumit Singh 2,692

#3
YUN ZHU Profile Picture

YUN ZHU 1,935 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans