web
You’re offline. This is a read only version of the page.
close
Skip to main content
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:

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,696 Moderator on at
    RE: The record in table Item already exists.

    Hi,

    Please visit to the Items page and first search this No. you are trying to insert.

    Thanks.

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

    Thank you for reply.

    I have already checked and item does not exist. Even I have already checked it using SQL Query but it does not find item which I am trying to insert.

  • Nitin Verma Profile Picture
    21,696 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.

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

    I have single company.

  • Nitin Verma Profile Picture
    21,696 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.

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

  • Suggested answer
    Teddy Herryanto (That NAV Guy) Profile Picture
    14,209 Super User 2025 Season 2 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.

  • 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

  • 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
    YUN ZHU Profile Picture
    93,438 Super User 2025 Season 2 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

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 2,204

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 1,933

#3
YUN ZHU Profile Picture

YUN ZHU 1,885 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans