Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to check if the data is already exist in the table and if the data is already exist do not update the table field with new data.

(0) ShareShare
ReportReport
Posted on by 506

Hello everyone,

How to check if the data is already exist in the table and if the data is already exist do not update the table field with new data.

that is Update the table record if the similar data is not there in the table field.

Thank You

Siddhant

*This post is locked for comments

  • Suggested answer
    Deepak Agarwal Profile Picture
    Deepak Agarwal 8,566 on at
    RE: How to check if the data is already exist in the table and if the data is already exist do not update the table field with new data.

    Hi Siddhant,

    I believe you posted same question twice, here is another link

    [View:https://community.dynamics.com/ax/f/microsoft-dynamics-ax-forum/360652/want-to-create-a-validation-if-a-record-is-already-exist-in-a-table:750:50]

    Now regarding your issue, if you want to prevent duplicate records than you need to create a index and set the property AllowDuplicates:No. You can add one or more fields in that index to achieve this requirement. See example of Custgroup table.

    pastedimage1563450580246v2.png

    Let me know if that helps.

    Thanks

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: How to check if the data is already exist in the table and if the data is already exist do not update the table field with new data.

    Seems you posted almost the same question two times.

    About the first part of your question: ("How to check if the data is already exist in the table"), please see my answer here: [View:https://community.dynamics.com/ax/f/microsoft-dynamics-ax-forum/360652/want-to-create-a-validation-if-a-record-is-already-exist-in-a-table/949095#949095:750:50]

    About your second question, you need to handle it in code, something like this. We assume thatyou have a table called MyTable, with fields Field1, Field2 and Field3. The first two fields determine the unique index of the table. If a record already exist with matchin FIeld1 and Field2 values, you want to update the record. Otherwise you want to insert a new record.

    You also need to implement "find" method in your table, which is a best practice for all new tables (just like the "exits" method that I mentioned in my other answer). 

    MyTable myTable = MyTable::find(value1, value2);
    if (myTable)
    {
        myTable.selectForUpdate(true);
        myTable.Field3 = value3;
        myTable.update();
    }
    else
    {
        myTable.clear();
        myTable.Field1 = value1;
        myTable.Field2 = value2;
        myTable.Field3 = value3;
        myTable.insert();
    }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,399 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans