Custom script failing for OOTB objects

Hi Team,

We have the below custom script which creates the entry into custom table CCCAccProdGroupInITShop but it is faling with error

I did a Visual Studio debug and the code which fails is when trying to save the new object:

entity = Session.Source().CreateNew("CCCAccProdGroupInITShop")
' Fill keys and values
entity.PutValue("UID_AccProductGroup", valUID_AccProductGroup)
entity.PutValue("UID_ITShopOrg", valUID_ITShopOrg)
entity.Save(Session)

the custom table CCCAccProdGroupInITShop does not have any logic in it (table scripts)

"#If Not SCRIPTDEBUGGER Then
References VI.DataImport.dll

Imports System.Collections.Generic
Imports System.IO
Imports System.Globalization
Imports VI.DB.Entities
Imports VI.DB.Specialized
Imports VI.DataImport
#End If

Public Sub CCC_Build_AccProductGroupInITShopOrg(ByVal connectionString As String)

' Table
Dim table = Connection.Tables("CCCAccProdGroupInITShop")

' Line counter
Dim counter As New LineCounter()

' Import from an external database
Dim lineProvider As ILineProvider
Dim dbLineProvider As New DbLineProvider()
dbLineProvider.ProviderName = "System.Data.SqlClient.SqlClientFactory, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=#############"
dbLineProvider.ConnectionString = connectionString
dbLineProvider.TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")

' SQL statement
Dim statement As New PlainSqlStatement()
statement.Statement = "select cu.UID_Org,ac.UID_AccProductGroup,ac.CCC_UID_ITShopOrg_Request " & _
"from accproduct ac " & _
"join basetree its on its.uid_accproduct = ac.uid_accproduct " & _
"join basetree bo on bo.uid_org = its.uid_parentorg " & _
"join basetree cu on bo.uid_parentorg = cu.uid_parentorg " & _
"where its.itshopinfo = N'PR' " & _
" AND bo.itshopinfo = N'BO' " & _
" AND cu.itshopinfo = N'CU' " & _
" and ac.isinactive = 0 " & _
" and ac.UID_AccProductGroup is not null " & _
"group by cu.UID_Org,ac.UID_AccProductGroup,ac.CCC_UID_ITShopOrg_Request " & _
"order by cu.UID_Org,ac.UID_AccProductGroup"

dbLineProvider.Statement = statement
lineProvider = dbLineProvider

' Column indices
Const iUID_AccProductGroup = 1
Const iUID_ITShopOrg = 0
Const iUID_ITShopOrg_LimitWhoCanSee = 2

' Resolver to get column data from import data
Dim columnUID_AccProductGroup As IResolveImportValue = New ResolveImportValueSimple("UID_AccProductGroup")
Dim columnUID_ITShopOrg As IResolveImportValue = New ResolveImportValueSimple("UID_ITShopOrg")

Try

'
' Create a dictionary for the destination table
'
Dim colImport As IEntityCollection
Dim elemsByKey As New Dictionary(Of String, IEntity)(StringComparer.OrdinalIgnoreCase)
Dim imported As New HashSet(Of DbObjectKey)()
Dim query As Query = Query.From("CCCAccProdGroupInITShop").SelectNone()

' Set keys and values as display items to load them with the collection
query = query.Select("UID_AccProductGroup")
query = query.Select("UID_ITShopOrg")
query = query.Select("xmarkedfordeletion")

' Load the collection
colImport = Session.Source().GetCollection(query, EntityCollectionLoadType.Slim)

' Put the entries in the dictionary
For Each elem In colImport
Dim key As String

key = elem.GetValue("UID_AccProductGroup").String _
& Chr(7) & elem.GetValue("UID_ITShopOrg").String _

If Not elemsByKey.ContainsKey(key) Then
elemsByKey.Add(key, elem)
End If
Next

Try
For Each line As Line In lineProvider.GetLines(counter)

' Pay attention to the Stop flag
If StopProcessing Then
Exit For
End If

Try
' Get raw data from the current line
Dim key As String
Dim valUID_AccProductGroup As String
Dim valUID_ITShopOrg As String
Dim valUID_ITShopOrgLimitWhoCanSee As String

Try
valUID_AccProductGroup = line.GetValue(iUID_AccProductGroup)
valUID_ITShopOrg = line.GetValue(iUID_ITShopOrg)

valUID_ITShopOrgLimitWhoCanSee = line.GetValue(iUID_ITShopOrg_LimitWhoCanSee)
If Not String.IsNullOrEmpty(valUID_ITShopOrgLimitWhoCanSee) Then
valUID_ITShopOrg = Connection.GetSingleProperty("ITShopOrg", "UID_ITShopOrg", _
String.Format("UID_ParentITShopOrg = '{0}' AND ITShopInfo = 'CU'", valUID_ITShopOrgLimitWhoCanSee))
End If
'
' Create key for this line
'
key = DbVal.ConvertTo(Of String)(valUID_AccProductGroup) _
& Chr(7) & DbVal.ConvertTo(Of String)(valUID_ITShopOrg) _

Catch ex As Exception
Throw New Exception(#LD("Error in line|{0}|{1}|{2}", line.OriginalLineNumber, ViException.ErrorString(ex), line.ToString())#)
End Try

Dim elem As IEntity = Nothing
Dim entity As IEntity = Nothing

If elemsByKey.TryGetValue(key, elem) Then
' Mark element for superset handling
imported.Add(New DbObjectKey(table, elem))
Else
entity = Session.Source().CreateNew("CCCAccProdGroupInITShop")

' Fill keys and values
entity.PutValue("UID_AccProductGroup", valUID_AccProductGroup)
entity.PutValue("UID_ITShopOrg", valUID_ITShopOrg)
entity.Save(Session)

' Include in our collection to avoid double imports of elements
elemsByKey(key) = entity
imported.Add(New DbObjectKey(table, entity))
End If
Catch ex As Exception
Throw New Exception(#LD("Error in line|{0}|{1}|{2}", line.OriginalLineNumber, ViException.ErrorString(ex), line.ToString())#)
End Try

Next ' ForEach line
Catch ex As Exception
Throw New Exception(#LD("Error in processing {0}", ViException.ErrorString(ex))#)
End Try

'
' Superset handling
'
For Each elem In colImport

Try
If imported.Contains(New DbObjectKey(table, elem)) Then
Continue For ' Found in the import
End If

Dim obj = elem.Create(Session)
obj.MarkForDeletion()
obj.Save(Session)

Catch ex As Exception
Throw New Exception(#LD("Error removing object {0}|{1}", elem.Display, ViException.ErrorString(ex))#)
End Try
Next

Catch ex As Exception
Throw New Exception(#LD("Error processing {0}", ViException.ErrorString(ex))#)
End Try

End Sub"

Error message

Error applying changes to database.
at VI.ObjectBrowser.Parts.SingleObjectGrid._SaveObject(Command cmd)
at VI.DB.Entities.EntitySingleDbObject.Save()
at VI.Base.SyncActions.Do[T1,T2](T1 p1, T2 p2, Func`3 action)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.EntitySingleDbObject.<>c.<<Save>b__36_0>d.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.EventUnitOfWork.<PutAsync>d__2.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.PermissionsUnitOfWork.<PutAsync>d__11.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.EventUnitOfWork.<PutAsync>d__2.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.UnitOfWorkImpl.<PutAsync>d__39.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.UnitOfWorkImpl.<_PutEntity>d__41.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.UnitOfWorkImpl.<FlushAsync>d__44.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.DbEntitySink.<FlushAsync>d__17.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.DbOperations.ClusteringDbOperationsQueue.<FlushAsync>d__31.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.DbOperations.ClusteringDbOperationsQueue.<_FlushInternalAsync>d__32.MoveNext()
Error running statement: insert into CCCAccProdGroupInITShop (UID_AccProductGroup, UID_ITShopOrg, xdateinserted, xuserinserted, xdateupdated, xuserupdated, xobjectkey) values ('fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f', 'QER-ITSHOPORG-DELEGATION-CU', GetUTCDate(), N'AX2\Admin_ADM', GetUTCDate(), N'AX2\Admin_ADM', '<Key><T>CCCAccProdGroupInITShop</T><P>fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f</P><P>QER-ITSHOPORG-DELEGATION-CU</P></Key>')
at VI.DB.Entities.DbOperations.ClusteringDbOperationsQueue.<_FlushInternalAsync>d__32.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.DbOperations.ClusteringDbOperationsQueue.<_FlushInternalAsync>d__32.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.DbOperations.ClusteringDbOperationsQueue.<_DoInsertsAsync>d__35.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.Entities.DbOperations.ClusteringDbOperationsQueue.<_RunSingleAsync>d__43.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.ReadWriteDbSession.<SqlExecuteNonQueryAsync>d__15.MoveNext()
Database error 2627: Violation of PRIMARY KEY constraint 'PK__CCCAccPr__EAFD3AEDE7AEC0D2'. Cannot insert duplicate key in object 'dbo.CCCAccProdGroupInITShop'. The duplicate key value is (fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f, QER-ITSHOPORG-DELEGATION-CU).
The statement has been terminated.
at VI.DB.DataAccess.ReadWriteDbSession.<SqlExecuteNonQueryAsync>d__15.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.ReadWriteDbSession.<IgnoreBrokenConnectionAsync>d__49`1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.ReadWriteDbSession.<_SqlExecuteNonQueryAsync>d__16.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.ReadOnlyDbSession.<ExecuteAndLogAsync>d__102`1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.ReadOnlyDbSession.<ExecuteAndLogAsync>d__103`1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.SafeDbCommand.<ExecuteNonQueryAsync>d__16.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at VI.DB.DataAccess.SafeDbCommand.<_CheckedAsync>d__43`1.MoveNext()
Violation of PRIMARY KEY constraint 'PK__CCCAccPr__EAFD3AEDE7AEC0D2'. Cannot insert duplicate key in object 'dbo.CCCAccProdGroupInITShop'. The duplicate key value is (fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f, QER-ITSHOPORG-DELEGATION-CU).
The statement has been terminated.
at VI.DB.DataAccess.SafeDbCommand.<_CheckedAsync>d__43`1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
at System.Data.SqlClient.SqlCommand.EndExecuteNonQueryAsync(IAsyncResult asyncResult)
at System.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult)
at System.Data.SqlClient.SqlCommand.InternalEndExecuteNonQuery(IAsyncResult asyncResult, String endMethod, Boolean isInternal)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

Crash report

2024-07-25 10:14:16 SqlLog (2 ms) - select UID_AccProductGroup, Ident_AccProductGroup, FullPath, xmarkedfordeletion from AccProductGroup where (AccProductGroup.UID_AccProductGroup = 'fad6c95c-2611-4587-bbaa-10dfcf3189e9')
2024-07-25 10:14:16 ObjectLog Collection: Run statement and fetch data done in 2ms.
2024-07-25 10:14:16 ObjectLog Collection.Count: 1
2024-07-25 10:14:16 ObjectLog Getting collection done in 3ms.
2024-07-25 10:14:16 ObjectLog ITShopOrg: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:16 SqlLog (2 ms) - select UID_ITShopOrg, Ident_Org, FullPath, xmarkedfordeletion from ITShopOrg where (ITShopOrg.UID_ITShopOrg = 'QER-ITSHOPORG-DELEGATION-CU')
2024-07-25 10:14:16 ObjectLog Collection: Run statement and fetch data done in 2ms.
2024-07-25 10:14:16 ObjectLog Collection.Count: 1
2024-07-25 10:14:16 ObjectLog Getting collection done in 2ms.
2024-07-25 10:14:16 ObjectLog Finding object classes for object fad6c95c-2611-4587-bbaa-10dfcf3189e9, QER-ITSHOPORG-DELEGATION-CU
2024-07-25 10:14:16 ObjectLog Is it member of entity class CCCAccProdGroupInITShop?
2024-07-25 10:14:16 ObjectLog Result: True
2024-07-25 10:14:16 ObjectLog AccProductGroup: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:16 SqlLog (9 ms) - select UID_AccProductGroup, Ident_AccProductGroup, FullPath, xmarkedfordeletion from AccProductGroup where (AccProductGroup.UID_AccProductGroup = 'fad6c95c-2611-4587-bbaa-10dfcf3189e9')
2024-07-25 10:14:16 ObjectLog Collection: Run statement and fetch data done in 10ms.
2024-07-25 10:14:16 ObjectLog Collection.Count: 1
2024-07-25 10:14:16 ObjectLog Getting collection done in 10ms.
2024-07-25 10:14:16 ObjectLog ITShopOrg: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:16 SqlLog (2 ms) - select UID_ITShopOrg, Ident_Org, FullPath, xmarkedfordeletion from ITShopOrg where (ITShopOrg.UID_ITShopOrg = 'QER-ITSHOPORG-DELEGATION-CU')
2024-07-25 10:14:16 ObjectLog Collection: Run statement and fetch data done in 2ms.
2024-07-25 10:14:16 ObjectLog Collection.Count: 1
2024-07-25 10:14:16 ObjectLog Getting collection done in 3ms.
2024-07-25 10:14:16 ObjectLog Permissions context for AccProductGroup is CCCAccProdGroupInITShop
2024-07-25 10:14:16 ObjectLog AccProductGroup: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:16 SqlLog (1 ms) - select UID_AccProductGroup, Ident_AccProductGroup, FullPath, xmarkedfordeletion from AccProductGroup where (AccProductGroup.UID_AccProductGroup = 'fad6c95c-2611-4587-bbaa-10dfcf3189e9')
2024-07-25 10:14:16 ObjectLog Collection: Run statement and fetch data done in 2ms.
2024-07-25 10:14:16 ObjectLog Collection.Count: 1
2024-07-25 10:14:16 ObjectLog Getting collection done in 2ms.
2024-07-25 10:14:16 ObjectLog Permissions context for ITShopOrg is CCCAccProdGroupInITShop
2024-07-25 10:14:16 ObjectLog ITShopOrg: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:16 SqlLog (1 ms) - select UID_ITShopOrg, Ident_Org, FullPath, xmarkedfordeletion from ITShopOrg where (ITShopOrg.UID_ITShopOrg = 'QER-ITSHOPORG-DELEGATION-CU')
2024-07-25 10:14:16 ObjectLog Collection: Run statement and fetch data done in 2ms.
2024-07-25 10:14:16 ObjectLog Collection.Count: 1
2024-07-25 10:14:16 ObjectLog Getting collection done in 2ms.
2024-07-25 10:14:27 ObjectLog Start caching of queries (level = 1).
2024-07-25 10:14:27 ObjectLog End caching of queries (level = 0).
2024-07-25 10:14:27 ObjectLog Removing query cache. Number of cached queries: 0
2024-07-25 10:14:28 SqlLog (20 ms) - select MessageType, MessageCode, SystemState from QBMVSystemState
2024-07-25 10:14:37 ObjectLog CCCAccProdGroupInITShop: Creating new entity, creation type Interactive
2024-07-25 10:14:37 ObjectLog Creating new entity done in 0ms.
2024-07-25 10:14:37 ObjectLog Old state: None, New state: PermissionBased
2024-07-25 10:14:37 ObjectLog Finding object classes for object ,
2024-07-25 10:14:37 ObjectLog Is it member of entity class CCCAccProdGroupInITShop?
2024-07-25 10:14:37 ObjectLog Result: True
2024-07-25 10:14:37 ObjectLog Start caching of queries (level = 1).
2024-07-25 10:14:37 ObjectLog End caching of queries (level = 0).
2024-07-25 10:14:37 ObjectLog Removing query cache. Number of cached queries: 0
2024-07-25 10:14:42 ObjectLog Begin transaction in read/write entity
2024-07-25 10:14:42 ObjectLog Check and execute column format Single Line with QER-ITSHOPORG-DELEGATION-CU
2024-07-25 10:14:42 ObjectLog CCCAccProdGroupInITShop.UID_ITShopOrg = QER-ITSHOPORG-DELEGATION-CU
2024-07-25 10:14:42 ObjectLog Check and execute column format Single Line with <Key><T>CCCAccProdGroupInITShop</T><P></P><P>QER-ITSHOPORG-DELEGATION-CU</P></Key>
2024-07-25 10:14:42 ObjectLog CCCAccProdGroupInITShop.XObjectKey = <Key><T>CCCAccProdGroupInITShop</T><P></P><P>QER-ITSHOPORG-DELEGATION-CU</P></Key>
2024-07-25 10:14:42 ObjectLog Commit transaction in read/write entity
2024-07-25 10:14:42 ObjectLog ITShopOrg: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:42 SqlLog (3 ms) - select UID_ITShopOrg, Ident_Org, FullPath, xmarkedfordeletion from ITShopOrg where (ITShopOrg.UID_ITShopOrg = 'QER-ITSHOPORG-DELEGATION-CU')
2024-07-25 10:14:42 ObjectLog Collection: Run statement and fetch data done in 4ms.
2024-07-25 10:14:42 ObjectLog Collection.Count: 1
2024-07-25 10:14:42 ObjectLog Getting collection done in 5ms.
2024-07-25 10:14:42 ObjectLog Permissions context for ITShopOrg is CCCAccProdGroupInITShop
2024-07-25 10:14:42 ObjectLog ITShopOrg: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:42 SqlLog (2 ms) - select UID_ITShopOrg, Ident_Org, FullPath, xmarkedfordeletion from ITShopOrg where (ITShopOrg.UID_ITShopOrg = 'QER-ITSHOPORG-DELEGATION-CU')
2024-07-25 10:14:42 ObjectLog Collection: Run statement and fetch data done in 2ms.
2024-07-25 10:14:42 ObjectLog Collection.Count: 1
2024-07-25 10:14:42 ObjectLog Getting collection done in 2ms.
2024-07-25 10:14:42 ObjectLog ITShopOrg: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:42 SqlLog (2 ms) - select UID_ITShopOrg, Ident_Org, FullPath, xmarkedfordeletion from ITShopOrg where (ITShopOrg.UID_ITShopOrg = 'QER-ITSHOPORG-DELEGATION-CU')
2024-07-25 10:14:42 ObjectLog Collection: Run statement and fetch data done in 2ms.
2024-07-25 10:14:42 ObjectLog Collection.Count: 1
2024-07-25 10:14:42 ObjectLog Getting collection done in 2ms.
2024-07-25 10:14:42 ObjectLog Start caching of queries (level = 1).
2024-07-25 10:14:42 ObjectLog End caching of queries (level = 0).
2024-07-25 10:14:42 ObjectLog Removing query cache. Number of cached queries: 0
2024-07-25 10:14:47 ObjectLog Start caching of queries (level = 1).
2024-07-25 10:14:47 ObjectLog End caching of queries (level = 0).
2024-07-25 10:14:47 ObjectLog Removing query cache. Number of cached queries: 0
2024-07-25 10:14:49 ObjectLog Begin transaction in read/write entity
2024-07-25 10:14:49 ObjectLog Check and execute column format Single Line with fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f
2024-07-25 10:14:49 ObjectLog CCCAccProdGroupInITShop.UID_AccProductGroup = fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f
2024-07-25 10:14:49 ObjectLog Check and execute column format Single Line with <Key><T>CCCAccProdGroupInITShop</T><P>fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f</P><P>QER-ITSHOPORG-DELEGATION-CU</P></Key>
2024-07-25 10:14:49 ObjectLog CCCAccProdGroupInITShop.XObjectKey = <Key><T>CCCAccProdGroupInITShop</T><P>fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f</P><P>QER-ITSHOPORG-DELEGATION-CU</P></Key>
2024-07-25 10:14:49 ObjectLog Commit transaction in read/write entity
2024-07-25 10:14:49 ObjectLog AccProductGroup: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:49 SqlLog (2 ms) - select UID_AccProductGroup, Ident_AccProductGroup, FullPath, xmarkedfordeletion from AccProductGroup where (AccProductGroup.UID_AccProductGroup = 'fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f')
2024-07-25 10:14:49 ObjectLog Collection: Run statement and fetch data done in 4ms.
2024-07-25 10:14:49 ObjectLog Collection.Count: 1
2024-07-25 10:14:49 ObjectLog Getting collection done in 4ms.
2024-07-25 10:14:49 ObjectLog ITShopOrg: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:49 SqlLog (2 ms) - select UID_ITShopOrg, Ident_Org, FullPath, xmarkedfordeletion from ITShopOrg where (ITShopOrg.UID_ITShopOrg = 'QER-ITSHOPORG-DELEGATION-CU')
2024-07-25 10:14:49 ObjectLog Collection: Run statement and fetch data done in 3ms.
2024-07-25 10:14:49 ObjectLog Collection.Count: 1
2024-07-25 10:14:49 ObjectLog Getting collection done in 3ms.
2024-07-25 10:14:49 ObjectLog Permissions context for AccProductGroup is CCCAccProdGroupInITShop
2024-07-25 10:14:49 ObjectLog AccProductGroup: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:49 SqlLog (2 ms) - select UID_AccProductGroup, Ident_AccProductGroup, FullPath, xmarkedfordeletion from AccProductGroup where (AccProductGroup.UID_AccProductGroup = 'fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f')
2024-07-25 10:14:49 ObjectLog Collection: Run statement and fetch data done in 2ms.
2024-07-25 10:14:49 ObjectLog Collection.Count: 1
2024-07-25 10:14:49 ObjectLog Getting collection done in 3ms.
2024-07-25 10:14:49 ObjectLog AccProductGroup: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:49 SqlLog (1 ms) - select UID_AccProductGroup, Ident_AccProductGroup, FullPath, xmarkedfordeletion from AccProductGroup where (AccProductGroup.UID_AccProductGroup = 'fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f')
2024-07-25 10:14:49 ObjectLog Collection: Run statement and fetch data done in 2ms.
2024-07-25 10:14:49 ObjectLog Collection.Count: 1
2024-07-25 10:14:49 ObjectLog Getting collection done in 2ms.
2024-07-25 10:14:49 ObjectLog ITShopOrg: Getting collection, load type: ForeignDisplays
2024-07-25 10:14:49 SqlLog (1 ms) - select UID_ITShopOrg, Ident_Org, FullPath, xmarkedfordeletion from ITShopOrg where (ITShopOrg.UID_ITShopOrg = 'QER-ITSHOPORG-DELEGATION-CU')
2024-07-25 10:14:49 ObjectLog Collection: Run statement and fetch data done in 2ms.
2024-07-25 10:14:49 ObjectLog Collection.Count: 1
2024-07-25 10:14:49 ObjectLog Getting collection done in 2ms.
2024-07-25 10:14:53 ObjectLog Session: Begin Transaction
2024-07-25 10:14:53 SqlLog (< 1 ms) - Pin DbSession to physical connection
2024-07-25 10:14:53 SqlLog (5 ms) - BEGIN TRANSACTION
2024-07-25 10:14:53 ObjectLog DB sink: Putting entity 'fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f, QER-ITSHOPORG-DELEGATION-CU' of table 'CCCAccProdGroupInITShop' with state PermissionBased into database queue (level 0)
2024-07-25 10:14:53 ObjectLog Begin transaction in read/write entity
2024-07-25 10:14:53 ObjectLog Interactive: OnSaving for fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f, QER-ITSHOPORG-DELEGATION-CU
2024-07-25 10:14:53 ObjectLog Db Operations Queue: Operation Insert on <Key><T>CCCAccProdGroupInITShop</T><P>fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f</P><P>QER-ITSHOPORG-DELEGATION-CU</P></Key> added to database queue (level 0).
2024-07-25 10:14:53 ObjectLog Interactive: OnSaved for fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f, QER-ITSHOPORG-DELEGATION-CU
2024-07-25 10:14:53 ObjectLog Commit transaction in read/write entity
2024-07-25 10:14:53 ObjectLog DB sink: Flushing database queue
2024-07-25 10:14:53 ObjectLog Db Operations Queue: Flush triggered from outside.
2024-07-25 10:14:53 ObjectLog Flushing 1 operations
2024-07-25 10:14:53 ObjectLog Flushing level 0
2024-07-25 10:14:53 SqlLog Setting DB context data to: user = AX2\Admin_ADM, id = 5894e7d9-836e-4b49-aee7-bd5fc82264d8, level = 0
2024-07-25 10:14:53 SqlLog (19 ms) - insert into CCCAccProdGroupInITShop (UID_AccProductGroup, UID_ITShopOrg, xdateinserted, xuserinserted, xdateupdated, xuserupdated, xobjectkey) values ('fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f', 'QER-ITSHOPORG-DELEGATION-CU', GetUTCDate(), N'AX2\Admin_ADM', GetUTCDate(), N'AX2\Admin_ADM', '<Key><T>CCCAccProdGroupInITShop</T><P>fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f</P><P>QER-ITSHOPORG-DELEGATION-CU</P></Key>')
2024-07-25 10:14:53 ObjectLog Session: Rollback Transaction
2024-07-25 10:14:53 SqlLog Resetting DB context data.
2024-07-25 10:14:53 SqlLog (7 ms) - ROLLBACK TRANSACTION
2024-07-25 10:14:53 SqlLog (53 ms) - Physical Transaction
2024-07-25 10:14:53 SqlLog (53 ms) - Pinned physical connection
2024-07-25 10:14:53 VI.FormBase.ExceptionMgr Error applying changes to database.

  •         : Could you please provide your insights on this error?

  • Well the stand-out for me is this:

    Violation of PRIMARY KEY constraint 'PK__CCCAccPr__EAFD3AEDE7AEC0D2'. Cannot insert duplicate key in object 'dbo.CCCAccProdGroupInITShop'. The duplicate key value is (fe8d1f6e-cd88-41f7-8ce3-4bb81c55374f, QER-ITSHOPORG-DELEGATION-CU).
    The statement has been terminated.

  •   This is the actual error messgae,

    It is failing when trying to create default assignments in custom table.

    We don't have any on-Saving scripts in Custom table but still the job is failing when trying to insert entry to custom table.

    ErrorMessages (2024-08-05 16:01:47.740) [810222] Error running script 'CCC_Build_AccProductGroupInITShopOrg'.
    [System.Exception] Error processing [System.Exception] Error in processing [System.Exception] Error in line|33|[810306] Error while running 'OnSaving' in logic module 'VI.DB.Entities.ModuleDependentLogic'.
    [810273] You are not allowed to create default objects or assignments.|"QER-ITSHOPORG-DELEGATION-CU";"QER-f33d9f6ec3e744a3ab69a474c10f6ff4";""
    at StdioProcessor.StdioProcessor._Execute(Job job)
    at VI.JobService.JobComponents.ScriptComponent.Activate(String task)
    at VI.JobService.JobComponents.ScriptComponent._TaskScriptExec()
    at VI.DB.Scripting.ScriptRunner.Eval(String key, Object[] parameters)
    ---- Start of Inner Exception ----
    at DynScripts.Scripts_k3fpaiBsy0sYRDA3B9NdDaudUTxuOCdH.CCC_Build_AccProductGroupInITShopOrg(String connectionString)

  • Hi,

    Well this is now a different error message to the first.  The error message is clear but I'm not sure why this would fire on a custom table unless it's configured as a global constraint. (I'm not big on triggers and constraints - tend to leave that to the product DEVs).

    So for now I'm out of ideas.

    B.