Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

BatchJob table insert error - The record already exists.

Posted on by 130

Hi friends,

I have faced recently following pretty weird issue during batch job creation from AIF integration port.

AIF inbound endpoint gets XML message then process it and try to create Batch job:

protected void addBatchTask(int _secondDelay)
{
    BatchHeader          batchHeader;
    SysRecurrenceData    sysRecurrenceData;
    BatchInfo            localBatchInfo;
    ;

    if (checkPostBatch)
    {
        batchHeader = batchHeader::construct();
        sysRecurrenceData = SysRecurrence::defaultRecurrence();
        sysRecurrenceData = SysRecurrence::setRecurrenceStartDateTime(sysRecurrenceData,
            DateTimeUtil::addSeconds(DateTimeUtil::utcNow(), _secondDelay));
        sysRecurrenceData = SysRecurrence::setRecurrenceEndAfter(sysRecurrenceData, 1);

        localBatchInfo = checkPostBatch.batchInfo();
        localBatchInfo.parmRetriesOnFailure(#NoOfRetriesOnFailure);
        batchHeader.addTask(checkPostBatch);
        batchHeader.parmRecurrenceData(sysRecurrenceData);
        batchHeader.parmAlerts(NoYes::No, NoYes::Yes, NoYes::No, NoYes::Yes, NoYes::No);
        batchHeader.save();
    }
}

Then AIF exception appears:

DuplicateKeyException: Cannot create a record in Batch Job (BatchJob). Job description: MES goods issue processing task, Waiting.
The record already exists.

batchHeader.save() method tries to insert new BatchJob record but without success.

Looks very strange because BatchJob table has Primary key -> RecId field.

Then I just try to execute following Job:

static void MESBatchJobTest(Args _args)
{
    batchJob batchJob;
    ;

    ttsbegin;
    batchJob.Status = BatchStatus::Waiting;
    batchJob.OrigStartDateTime = dateTimeUtil::getSystemDateTime();
    batchJob.Caption = "TEST MES goods issue processing task TEST";
    batchJob.insert();
    ttscommit;
}

and getting the same exception:

JobInsertError.png

Does anyone encountered anything similar earlier?

Any suggestions are welcome!

*This post is locked for comments

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: BatchJob table insert error - The record already exists.

    Each AOS has RecId cache, you can flush it with AOS restart, maybe something get wrong there and they have incorrect next recid value in the cache.

  • JayAXDinamics Profile Picture
    JayAXDinamics 130 on at
    RE: BatchJob table insert error - The record already exists.

    Hi Ievgen,

    Thanks for reply,

    I have checked, there are no any customizations on BatchJob table in the system.

    DuplicateKeyException is arisen during execution in batch job. System configuration has 2 Batch servers.

    May be it depends on Batch server instance somehow?

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: BatchJob table insert error - The record already exists.

    Hi Evgeny Ermachenok,

    Check that there is no customized indexes, no customizations in aosValidateInsert and that RecId generated is actually unique ReciD.

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans