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 :
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 518

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

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    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();
    }
  • Suggested answer
    Deepak Agarwal Profile Picture
    8,602 on at

    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

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans