Monday, 11 October 2021

cannot create a record in customers (custtable the record already exists)

Go to SQL as Admin, AXDB database:

pass your table(Custable) and run below query:

DECLARE @MaxRecID BIGINT
DECLARE @NextVal BIGINT
 
SELECT @MaxRecID = MAX(RECID)
FROM custtable
 
SELECT @NextVal = NEXTVAL
FROM SYSTEMSEQUENCES
INNER JOIN SQLDICTIONARY
ON SQLDICTIONARY.FIELDID = 0
AND SQLDICTIONARY.name = 'custtable'
AND SQLDICTIONARY.TABLEID = SYSTEMSEQUENCES.TABID
 
IF (@NextVal > @MaxRecID)
BEGIN
PRINT 'custtable did not need to be updated.'
END
ELSE
BEGIN
PRINT 'Updated custtable from ' + CONVERT(VARCHAR(MAX), @NextVal) + '' to '' + CONVERT(VARCHAR(MAX), @MaxRecID + 1)
UPDATE SYSTEMSEQUENCES
SET NEXTVAL = @MaxRecID + 1
FROM SYSTEMSEQUENCES
INNER JOIN SQLDICTIONARY
ON SQLDICTIONARY.FIELDID = 0
AND SQLDICTIONARY.name = 'custtable'
AND SQLDICTIONARY.TABLEID = SYSTEMSEQUENCES.TABID
END

No comments:

Post a Comment

POSTMAN D365

  Postman is useful to test the behavior of different OData class from/to D365FO. In this post we will see the steps to setup Postman with D...