Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

The record in table Item already exists.

(0) ShareShare
ReportReport
Posted on by 34

Hello Everyone,

I am getting error when try to insert Item using simple code. Error is prompted at Item.INSERT statement.

Customer is using Business Central 14 cu 21 and using Azure SQL Server.

I have checked SQL and there is no addition store procedure written on Item Insert.

Any help/suggestion is appreciated to resolve the issue.

pastedimage1655344145871v1.png

pastedimage1655344180204v2.png

pastedimage1655344255401v3.png

pastedimage1655344260605v4.png

Full Event Log:

Server instance: BC140
Category: Runtime
ClientSessionId: {2ca8e97c-3e8b-46d9-b107-7a6b4a1935ed}
ClientActivityId: {08ce6969-d767-4cc5-9f9e-e96e66eeaab4}
ServerSessionUniqueId: {a48d0c82-e5a3-408e-b7ac-d644d8589017}
ServerActivityId: {bc3db545-2c51-4064-9fda-79b5c71743a0}
EventTime: ‎2022‎-‎06‎-‎16T01:49:19.278433400Z
Message (NavCSideDuplicateKeyException): ParentException: NavCSideDuplicateKeyException
The record in table Item already exists. Identification fields and values: No.='90000026979'
ExceptionStackTrace:
at Microsoft.Dynamics.Nav.Runtime.NavApplicationMethod.InvokeMethod(ITreeObject obj, String methodName, Object[] args, Boolean resolveHandler, Boolean throwOnNotFound)
at Microsoft.Dynamics.Nav.Runtime.NavForm.RaiseOnAction(Nullable`1 actionId, String actionTriggerMethodName)
at Microsoft.Dynamics.Nav.Service.NSField.<>c__DisplayClass14_0.<ActionField>b__0(NsDataAccess recDataAccess)
at Microsoft.Dynamics.Nav.Service.NsFormDataAccess.RunWithFormDataAccess[T](ITreeObject parent, NavForm form, Func`2 func)
at Microsoft.Dynamics.Nav.Service.NsDataAccess.RunWithDataAccess[T](ITreeObject parent, NavRecordState state, Boolean instantiateNewForm, Guid parentFormHandle, String parentControlName, Boolean& instantiatedForm, Func`2 func)
at Microsoft.Dynamics.Nav.Service.NsDataAccess.RunWithDataAccess[T](ITreeObject parent, NavRecordState state, Func`2 func)
at Microsoft.Dynamics.Nav.Service.NSField.Action(NavSession session)
at SyncInvokeActionField(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.RunInTransactionCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.TransientErrorRetryCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.ErrorMappingCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
InnerException:
ParentException: TargetInvocationException
Exception has been thrown by the target of an invocation.
ExceptionStackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Dynamics.Nav.Runtime.NavApplicationMethod.InvokeMethod(ITreeObject obj, String methodName, Object[] args, Boolean resolveHandler, Boolean throwOnNotFound)
InnerException:
RootException: NavCSideDuplicateKeyException
The record in table Item already exists. Identification fields and values: No.='90000026979'
ExceptionStackTrace:
at Microsoft.Dynamics.Nav.Runtime.RecordImplementationHelper.MapException(NavCSideException originalException, NavDatabase database, Int32 companyToken, NCLMetaTable metaTable, IRecordBuffer recordBuffer, Boolean makeNewExceptionRemappable)
at Microsoft.Dynamics.Nav.Runtime.RecordImplementation.MapException(NavCSideException exception, IRecordBuffer recordBuffer, Boolean makeNewExceptionRemappable)
at Microsoft.Dynamics.Nav.Runtime.RecordImplementation.InsertRecord(DataError errorLevel)
at Microsoft.Dynamics.Nav.Runtime.NavRecord.Insert(DataError errorLevel, Boolean runApplicationTrigger, Boolean runGlobalTrigger)
at Microsoft.Dynamics.Nav.Runtime.NavRecord.ALInsert(DataError errorLevel, Boolean runApplicationTrigger)
at Microsoft.Dynamics.Nav.BusinessApplication.Page50035.a60Action1000000001a62_a45_OnAction_Scope.OnRun()
at Microsoft.Dynamics.Nav.Runtime.NavMethodScope.Run()
at Microsoft.Dynamics.Nav.BusinessApplication.Page50035.a60Action1000000001a62_a45_OnAction()
CallerStackTrace:
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.ErrorMappingCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.PushPopCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationTracer.TraceScopeCombinator(Category telemetryCategory, ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass10_0.<PerformanceCounterCombinator>b__0()
at Microsoft.Dynamics.Nav.Runtime.NavPerformanceCounterSetter.UpdatePerformanceCountersWithAverageServiceOperationDuration(Stopwatch stopWatch, Action action)
at Microsoft.Dynamics.Nav.Runtime.NavPerformanceCounterSetter.UpdatePerformanceCountersWithAverageServiceOperationAction(Action action, NavSession session)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.PerformanceCounterCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.InitClientTelemetryIdsCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.TlsClearCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.<>c__DisplayClass28_1.<Combine>b__1(NSServiceBase serviceInstance, Object[] inputs, Object[]& outputs)
at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
at System.ServiceModel.Dispatcher.MessageRpc.Wrapper.Resume(Boolean& alreadyResumedNoLock)
at System.ServiceModel.Dispatcher.ThreadBehavior.ResumeProcessing(IResumeMessageRpc resume)
at Microsoft.Dynamics.Nav.Runtime.NavSynchronizationContext.<>c__DisplayClass1_0.<ClearThreadLocalStorageDelegate>b__0(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()


ProcessId: 10688
Tag: 00000HC
ThreadId: 113
CounterInformation:

  • Jadigo91 Profile Picture
    5 on at
    The record in table Item already exists.
    I see that the post is old, but I've been having this same error for a long time and I want to post an answer in case it can help someone in the future.
     
    I have been reading a lot about Dynamics BC, and I have seen that, for example, the Item Table works with a table that fills in internal IDs for each Item, if that table is not filled in, the Items are not displayed in BC, BC can´t find them, and we get the error that the Item already exists if you try to Insert the Item, this may be because a record has been inserted in the Item table only with SQL, but not in the table containing the IDs
     
    In my case, the table that I need to fill in for the Items to be displayed correctly is [dbo].[Item$c526b3e9-b8ca-4683-81ba-fcd5f] , once I have inserted the records through SQL with a query, the problem has been solved, the products appear in BC instantly and the error that the Item already exists in BC no longer appears
     
    I hope this can help and that no one has to waste a lot of time looking for a solution to this problem.
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: The record in table Item already exists.

    Have you checked that your Item2 variable is not defined as temporary variable?

    If that is the case you will get this behavior.

  • Suggested answer
    YUN ZHU Profile Picture
    85,432 Super User 2025 Season 1 on at
    RE: The record in table Item already exists.

    Hi, I tested your code in BC v20 with no problems.

    pastedimage1655426055117v1.png

    it's a little weird. I think you can try the following two things. (Only for test)

    1. Try adding a Commit.

    pastedimage1655426136809v2.png

    2. Execute the code in OnDelete trigger. Maybe there are other customizations.

    pastedimage1655426201615v3.png

    Hope this helps.

    Thanks.

    ZHU

  • DipakPatel2505 Profile Picture
    34 on at
    RE: The record in table Item already exists.

    Insert is not executed multiple times.

    Also, I have cleared, init, reset variable in actual code but I am still getting the error.

    I have verified that Item does not exist before insert statement but still getting error.

    Below code is written in CodeUnit and testing scenario.

    pastedimage1655414721939v2.png

  • Suggested answer
    Francisco Bedolla Profile Picture
    1,119 on at
    RE: The record in table Item already exists.

    Usually you need to follow the next pattern:

    reset table, this clean any previous filter item.reset;

    set range the table with the new item number item.setrange("No.",value);

    if you not find the record, then item.no := value, if not item.findset then  item."no." := value;

    table. insert(true)   item.insert(true);

    you can add an else statement using else but isnt necessary and you dont need to INIT the table

  • Suggested answer
    Teddy Herryanto (That NAV Guy) Profile Picture
    13,742 Moderator on at
    RE: The record in table Item already exists.

    If the record doesn't exist before you run the code, check if you actually run the insert code twice.

    Try to run debug to see why it is causing that.

  • DipakPatel2505 Profile Picture
    34 on at
    RE: The record in table Item already exists.

    Testing Code is written on Codeunit - OnRun trigger and running codeunit directly.

  • Nitin Verma Profile Picture
    21,567 Moderator on at
    RE: The record in table Item already exists.

    Can you please tell me in which trigger you have written this code?

    Thanks.

  • DipakPatel2505 Profile Picture
    34 on at
    RE: The record in table Item already exists.

    I have single company.

  • Nitin Verma Profile Picture
    21,567 Moderator on at
    RE: The record in table Item already exists.

    Hi,

    Do you have single company operating? if there are multiple company please check in each company as well.

    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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans