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

Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None. The record already exists.

(0) ShareShare
ReportReport
Posted on by 15

While creating a new purchase order / sales order lines in system, the system is not generating a reference in source document line. Also, when tried to create a manual record in source document line, system is not generating a recid. MS Dynamics Ax 2012 R3.

Error Messages:

1-

Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 345, None.
The record already exists.

2-

Microsoft.Dynamics.Ax.Xpp.DuplicateKeyException: Exception of type 'Microsoft.Dynamics.Ax.Xpp.DuplicateKeyException' was thrown.
at Microsoft.Dynamics.Ax.MSIL.Interop.throwException(Int32 ExceptionValue)
at Microsoft.Dynamics.Ax.MSIL.cqlCursorIL.insert(IntPtr table)
at Dynamics.Ax.Application.SourceDocumentLine.insertSourceDocumentLine(Int64 _sourceDocumentHeaderRecId, Int32 _sourceRelationType, String _typeEnumName, Int32 _typeEnumValue, Date _exchangeRateDate, Int64 _parentSourceDocumentLine, Boolean , Boolean ) in SourceDocumentLine.insertSourceDocumentLine.xpp:line 19
at Dynamics.Ax.Application.SourceDocumentLine.insertSourceDocumentLine(Int64 _sourceDocumentHeaderRecId, Int32 _sourceRelationType, String _typeEnumName, Int32 _typeEnumValue, Date _exchangeRateDate, Int64 _parentSourceDocumentLine)
at Dynamics.Ax.Application.SourceDocumentLineStateNone.Dotransition() in SourceDocumentLineStateNone.doTransition.xpp:line 14
at Dynamics.Ax.Application.SourceDocumentStateBase.Transition() in SourceDocumentStateBase.transition.xpp:line 27
at Dynamics.Ax.Application.SourceDocumentStateBase.Performtransitionormaintenance() in SourceDocumentStateBase.performTransitionOrMaintenance.xpp:line 7
at Dynamics.Ax.Application.SourceDocumentLineState.Performtransitionormaintenance() in SourceDocumentLineState.performTransitionOrMaintenance.xpp:line 3
at Dynamics.Ax.Application.SourceDocumentStateBase.Transitionto() in SourceDocumentStateBase.transitionTo.xpp:line 22
at Dynamics.Ax.Application.SourceDocumentProcessorBase.Submit() in SourceDocumentProcessorBase.submit.xpp:line 11
at Dynamics.Ax.Application.SourceDocumentLineProcessor.submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, String _user, Boolean _isStatusPropagating, Boolean _maintenanceOnly, RecordInsertList _accountingDistributionInsertList, AccountingDistributionList _parentAccountingDistributionList, systemSequence _systemSequence, SourceDocumentLineItem _sourceDocumentLineItem, RecordInsertList _sourceDocumentLineTmpInsertList, Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean ) in SourceDocumentLineProcessor.submitSourceDocumentLineImplementation.xpp:line 135
at Dynamics.Ax.Application.SourceDocumentLineProcessor.@submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, String _user, Boolean _isStatusPropagating, Boolean _maintenanceOnly, RecordInsertList _accountingDistributionInsertList, AccountingDistributionList _parentAccountingDistributionList, systemSequence _systemSequence, SourceDocumentLineItem _sourceDocumentLineItem, Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean )
at Dynamics.Ax.Application.SourceDocumentLineProcessor.@submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, String _user, Boolean _isStatusPropagating, Boolean _maintenanceOnly, RecordInsertList _accountingDistributionInsertList, AccountingDistributionList _parentAccountingDistributionList, systemSequence _systemSequence, Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean )
at Dynamics.Ax.Application.SourceDocumentLineProcessor.@submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, String _user, Boolean _isStatusPropagating, Boolean _maintenanceOnly, RecordInsertList _accountingDistributionInsertList, AccountingDistributionList _parentAccountingDistributionList, Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean )
at Dynamics.Ax.Application.SourceDocumentLineProcessor.@submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, String _user, Boolean _isStatusPropagating, Boolean _maintenanceOnly, RecordInsertList _accountingDistributionInsertList, Boolean , Boolean , Boolean , Boolean , Boolean , Boolean , Boolean )
at Dynamics.Ax.Application.SourceDocumentLineProcessor.@submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, String _user, Boolean _isStatusPropagating, Boolean _maintenanceOnly, Boolean , Boolean , Boolean , Boolean , Boolean , Boolean )
at Dynamics.Ax.Application.SourceDocumentLineProcessor.@submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, String _user, Boolean _isStatusPropagating, Boolean , Boolean , Boolean , Boolean , Boolean )
at Dynamics.Ax.Application.SourceDocumentLineProcessor.@submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, String _user, Boolean , Boolean , Boolean , Boolean )
at Dynamics.Ax.Application.SourceDocumentLineProcessor.submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, String _user)
at Dynamics.Ax.Application.SourceDocumentProcessorFacade.submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, String _user, Boolean , Boolean , Boolean , Boolean ) in SourceDocumentProcessorFacade.submitSourceDocumentLineImplementation.xpp:line 26
at Dynamics.Ax.Application.SourceDocumentProcessorFacade.@submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, SourceDocumentProcessorCaller _caller, Boolean , Boolean , Boolean )
at Dynamics.Ax.Application.SourceDocumentProcessorFacade.@submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, SourceDocumentLineAccountingStatus _targetSourceDocumentLineAccountingStatus, Boolean , Boolean )
at Dynamics.Ax.Application.SourceDocumentProcessorFacade.@submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation, Boolean _updateImplementation, Boolean )
at Dynamics.Ax.Application.SourceDocumentProcessorFacade.submitSourceDocumentLineImplementation(SourceDocumentLineImplementation _sourceDocumentLineImplementation)
at Dynamics.Ax.Application.PurchTableType.Insert(Boolean _interCompanySilent, Date _accountingDate, Boolean , Boolean ) in PurchTableType.insert.xpp:line 53
at Dynamics.Ax.Application.PurchTableType.Insert(Boolean _interCompanySilent, Date _accountingDate)
at Dynamics.Ax.Application.PurchTable.Insert(Boolean _interCompanySilent, Date _accountingDate, Boolean , Boolean ) in PurchTable.insert.xpp:line 7
at Dynamics.Ax.Application.PurchTable.@Insert(Boolean _interCompanySilent, Boolean )
at Dynamics.Ax.Application.PurchTable.Insert(Boolean _interCompanySilent)
at Dynamics.Ax.Application.PurchCreateOrderForm.writeOnServer(Object[] _params) in PurchCreateOrderForm.writeOnServer.xpp:line 42
at PurchCreateOrderForm::writeOnServer(Object[] )
at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)
at Dynamics.Ax.Application.SysDictClass.invokeStaticMethod(Object[] _params) in SysDictClass.invokeStaticMethod.xpp:line 26
at SysDictClass::invokeStaticMethod(Object[] )
at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)
at Microsoft.Dynamics.Ax.Xpp.PredefinedFunctions.runAsInvoke(String className, String staticMethodName, Object[] parms, Object[]& exportInfolog)

  • AdnanShahid Profile Picture
    15 on at
    RE: Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None. The record already exists.

    Hello Ludwig,

    Sorry for late reply for I was having login issue.

    Yes, the issue is fixed by increment in SYSTEMSEQUENCES RECID increment by 1 for SOURCEDOCUMENTLINE.

    Thank you for being kind.

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None. The record already exists.

    Hello Adnan,

    Have you been able to get this issue fixed?

    Would be great if you could let us know if any other help is needed.

    Many thanks,

    Ludwig

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None. The record already exists.

    Hello AdnanShaid,

    In addition, what happens if you create another sales order for the same customer with the same item.

    Do you receive the same error message?

    Best regards,

    Ludwig

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    294,261 Super User 2025 Season 1 on at
    RE: Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None. The record already exists.

    Hi Adnan,

    Do you know if something changed recently? E.g. someone updated production with new customizations?

    You can also check the table SysSequences if you hit the maximum value. If you can't find it quickly, you can create an incident for Microsoft Support.

  • AdnanShahid Profile Picture
    15 on at
    RE: Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None. The record already exists.

    update :

    I ran consistency check and along with exceptions following error is observed,

    "Item number 000253 Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None.

    The record already exists."

    And 

    Sales order: SO-000000029, EST102

    Cannot edit a record in Order lines (SalesLine).
    The operation cannot be completed, since the record was not selected for update. Remember TTSBEGIN/TTSCOMMIT as well as the FORUPDATE clause.

    (S)\Classes\xRecord\doUpdate
    (S)\Classes\SalesLineType\update - line 222
    (S)\Data Dictionary\Tables\SalesLine\Methods\update - line 27
    (S)\Data Dictionary\Tables\SalesLine\Methods\validateWrite_server - line 135
    (S)\Data Dictionary\Tables\SalesLine\Methods\validateWrite - line 7
    (S)\Classes\SysConsistencyCheck\kernelCheckRecord - line 23
    (S)\Classes\SalesConsistencyCheck\checkFixSalesLine - line 43
    (S)\Classes\SalesConsistencyCheck\run - line 10
    (S)\Classes\SysConsistencyCheckJob\runClass - line 29
    (S)\Classes\SysConsistencyCheckJob\runClass - line 25
    (S)\Classes\SysConsistencyCheckJob\run - line 14
    (S)\Classes\SysConsistencyCheckJob\main - line 11

  • AdnanShahid Profile Picture
    15 on at
    RE: Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None. The record already exists.

    Hello André,

    It has been working since an year in my production environment and it has been working smoothly until this incident.

  • AdnanShahid Profile Picture
    15 on at
    RE: Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None. The record already exists.

    Thank you Ludwig for your kind response. I checked and the same issue is not listed there.

  • André Arnaud de Calavon Profile Picture
    294,261 Super User 2025 Season 1 on at
    RE: Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None. The record already exists.

    Hi Adnan,

    If you can't find any known issue on LCS Issue Search, I would suggest to check if you have the latest available kernel files installed. If so, you can contact Microsoft Support.

    Besides, I wonder if this was working before and if it is happening in your production environment.

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Cannot create a record in Source document line (SourceDocumentLine). Reference table ID: 340, None. The record already exists.

    Hi,

    This issue might be related to a system bug.

    Have you already checked the hotfixes that have been released on LCS?

    Please see:

    fix.lcs.dynamics.com/.../Results

    Best regards,

    Ludwig

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,013 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans