Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

How to check Duplicate Records using AL code?

(0) ShareShare
ReportReport
Posted on by 1,707

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.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 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

  • Inkey Solutions Profile Picture
    Inkey Solutions 1,707 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
    Nitin Verma 21,091 Super User 2024 Season 1 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
    Inkey Solutions 1,707 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
    Nitin Verma 21,091 Super User 2024 Season 1 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
    Inkey Solutions 1,707 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
    Nitin Verma 21,091 Super User 2024 Season 1 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
    Inkey Solutions 1,707 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
    Nitin Verma 21,091 Super User 2024 Season 1 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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans