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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Prevent duplicate record

(0) ShareShare
ReportReport
Posted on by 40

Greetings all,

I want to add a new method in my table to prevent the same value in the column from showing up. what method should i use?

I have the same question (0)
  • Suggested answer
    greengrimms Profile Picture
    1,400 on at

    Hi,

    That can be achieved by adding an index to the table. Just add the field/s that make up the key, and set the property Allow duplicates to No for that key.

  • fireblaster Profile Picture
    40 on at

    I already done it but, it keep inserting the same value of ID

  • greengrimms Profile Picture
    1,400 on at
    [deleted]
  • greengrimms Profile Picture
    1,400 on at

    Right, so the index itself won't generate a new Id for you, it'll only prevent duplicates from being inserted in the database by throwing an exception.

    What's your specific requirement? Remember you already have RecId for unique records, is this Id you created a numeric value that you want to auto increment just to show to the user? Is it a natural key?

  • fireblaster Profile Picture
    40 on at

    the ID that i created have a string value, so when i inserted into my table, it will filter out the same ID if existed

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi fireblaster,

    what do you mean "filter out"? Earlier you wrote "prevent the same value in the column from showing up".

    You also wrote "it keep inserting the same value of ID"

    I think it would be good if you could share a bit more details about your scenario. What's "it"? How is this data created and where?

    Unique indexes are the standard way to prevent duplicates - not only in AX but in databases in general.

    I warmly recommend that you stick with the logic of the standard application, this way it's easy for the users to understand how things work. Users can try to insert duplicate records, and they will see an error if they try to do so.

    It's up to the user (or your code, depending how the data is created) to handle the error or check for duplicates. The target table's responsibility is to prevent duplicates from being inserted, by throwing an error.

  • fireblaster Profile Picture
    40 on at

    Hi Nikolaos

    Sorry, when I said "filter out", it means that the table keeps inserting the same ID (which is the unique index I just did on the table that I want).

    so basically this data is created from importing .csv files, this import method is placed in a class. there's also a form and a button in it to import the files. the form and data source(same table) has 2 columns which one of is ID, so when I successfully imported the .csv file, the table or form appear to have duplicated records that have the same ID

    and quoting for the "it keeps inserting the same value of ID", it means that the .csv file contains various records with the same ID

    (eg: location    ID

          address     1

          city            1

    ,I just want to filter the records to select only one value of ID (doesn't matter which record because i have a second form to show all the record) to appear on my table

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Since it's your own code, just add code that checks whether a duplicate record already exists in the table. If it does, don't insert a new row.

    Please check this doc page to learn how to select (find) records in a table: hdocs.microsoft.com/.../select-statements

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans