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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Duplicate Records Validation Required before inserting data into a table using batch job class

(0) ShareShare
ReportReport
Posted on by 353

Hi -

  I have a batch class which reads the info log messages from BatchHistoryTable and inserts them into a Custom Regular table using insert(). The job works fine. I just need to put a validation that the records don't repeat depending on these three fields.

Document #

Employee ID

Assignment Date

I want to have a check in my batch class which reads the data in a Custom table before inserting.

If Document#, EmployeeID and Assignment are not found in a table for a single record then insert() or else no. In other works these three fields should always be unique for every row in a table.

How can I achieve this functionality thourgh X++ ? or f there is any other way of doing this ?

Please let me know if my question is not properly asked and I will do my best to elaborate further.

Thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    Hi Muhammad_Ali,

    First of all, create new index with these 3 fields and set allowDuplicates = No. This will prevent any code inserting a duplicate and throw an error. Now when you have index in place before inserting data into the table do a select by these 3 fields and if there is nothing in DB then do insert.

  • Muhammad_Ali Profile Picture
    353 on at

    Thanks Ievgen  

      I made indexes for the three fields and did as you said. Now my job runs fine and inserts data accordingly. I have tried sending the duplicate data to the table for testing and duplicates were not inserted. As they shouldnt!!

    Thanks

  • faiz7049 Profile Picture
    2,430 on at

    Hi Muhammad_Ali,

    I have same scenario . Can you share Job X++ code please.

  • Muhammad_Ali Profile Picture
    353 on at

    Hi Faiz

    I can do it monday morning. I dont have access to the system as of now.

    Thanks

  • Muhammad_Ali Profile Picture
    353 on at

    X++ code for exactly which part ? Code validation ?

  • faiz7049 Profile Picture
    2,430 on at

    Hi Ali,

    I need both. Insert info message to Custom table and validation.

  • Swetha Profile Picture
    5 on at

    Hello All,

    I am facing an issue with batch jobs in AX.

    My batch jobs creates invoice records and is a near real time batch job that runs every 5 mins. 

    we are seeing duplicate invoices being created when we invoke the batch job concurrently. That is 2 users manually triggering it through the periodic. This behaviour also occurs when batch job runs through batch server, while any user triggers it from periodic as well.

    I have  question here

    These are inserts happening on the custinvoiceJour table. Essentially, the expectation is, no matter 2 users have triggered this concurrently, we want to make sure that they system does not duplicate the invoice records.

    On the cust invoice jour table, there is already a index with allow duplicates as No. What is the possible solution here? 

    @Ivegen - Do i have to validate each records existing before i perform an insertion? Shouldnt this be automatically handled by the index constraints already in place?

    Any points are much appreciated.

    Thanks,

    Swetha K Desai

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 26

#2
imran ul haq Profile Picture

imran ul haq 8

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 4 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans