On PO confirmation, we are getting below error:
The source document lines cannot be finalized until the status is Confirmed.
The state of the source document or source document line could not be updated.
Purchase order is created from approved PR and is in Approved status. When user is trying to confirm this order, we are getting above error.
To fix the issue on UAT or SandBox system please run below query on SQL. Also below query impact 'VENDINVOICEJOUR', 'CUSTINVOICEJOUR' and 'PURCHREQTABLE'
--Find query
SELECT *
FROM SOURCEDOCUMENTHEADER SDH
JOIN SQLDICTIONARY SD ON SD.TABLEID = SDH.SOURCERELATIONTYPE AND SD.FIELDID = 0 AND SD.SQLNAME IN('VENDINVOICEJOUR', 'CUSTINVOICEJOUR', 'PURCHREQTABLE')
JOIN ACCOUNTINGEVENT AE ON AE.SOURCEDOCUMENTHEADER = SDH.RECID AND AE.STATE = 3
WHERE SDH.ACCOUNTINGSTATUS = 1 AND NOT EXISTS
(SELECT TOP 1 SOURCEDOCUMENTHEADER FROM ACCOUNTINGEVENT WHERE ACCOUNTINGEVENT.SOURCEDOCUMENTHEADER = SDH.RECID AND ACCOUNTINGEVENT.STATE = 0)
Mitigation Steps:
Please execute below statements:
--Update Accounting Distribution table
DELETE ACCOUNTINGDISTRIBUTION WHERE SOURCEDOCUMENTHEADER IN(
SELECT SDH.RECID FROM SOURCEDOCUMENTHEADER SDH
JOIN SQLDICTIONARY SD ON SD.TABLEID = SDH.SOURCERELATIONTYPE AND SD.FIELDID = 0 AND SD.SQLNAME IN('VENDINVOICEJOUR', 'CUSTINVOICEJOUR', 'PURCHREQTABLE')
JOIN ACCOUNTINGEVENT AE ON AE.SOURCEDOCUMENTHEADER = SDH.RECID AND AE.STATE = 3
WHERE SDH.ACCOUNTINGSTATUS = 1 AND NOT EXISTS
(SELECT TOP 1 SOURCEDOCUMENTHEADER FROM ACCOUNTINGEVENT WHERE ACCOUNTINGEVENT.SOURCEDOCUMENTHEADER = SDH.RECID AND ACCOUNTINGEVENT.STATE = 0)
GROUP BY SDH.RECID, SDH.ACCOUNTINGSTATUS, SDH.SOURCERELATIONTYPE, SDH.TYPEENUMNAME, SDH.TYPEENUMVALUE, SD.SQLNAME, AE.ACCOUNTINGDATE, AE.STATE, AE.RECID)
AND ACCOUNTINGEVENT = 0
--Update SourceDocumentLine table
UPDATE SOURCEDOCUMENTLINE
SET ACCOUNTINGSTATUS = 4
WHERE SOURCEDOCUMENTHEADER IN(
SELECT SDH.RECID FROM SOURCEDOCUMENTHEADER SDH
JOIN SQLDICTIONARY SD ON SD.TABLEID = SDH.SOURCERELATIONTYPE AND SD.FIELDID = 0 AND SD.SQLNAME IN('VENDINVOICEJOUR', 'CUSTINVOICEJOUR', 'PURCHREQTABLE')
JOIN ACCOUNTINGEVENT AE ON AE.SOURCEDOCUMENTHEADER = SDH.RECID AND AE.STATE = 3
WHERE SDH.ACCOUNTINGSTATUS = 1 AND NOT EXISTS
(SELECT TOP 1 SOURCEDOCUMENTHEADER FROM ACCOUNTINGEVENT WHERE ACCOUNTINGEVENT.SOURCEDOCUMENTHEADER = SDH.RECID AND ACCOUNTINGEVENT.STATE = 0)
GROUP BY SDH.RECID, SDH.ACCOUNTINGSTATUS, SDH.SOURCERELATIONTYPE, SDH.TYPEENUMNAME, SDH.TYPEENUMVALUE, SD.SQLNAME, AE.ACCOUNTINGDATE, AE.STATE, AE.RECID)
AND ACCOUNTINGSTATUS = 3
--Delete the SourceDocumentLine records in accounting status of 1
DELETE SOURCEDOCUMENTLINE
WHERE SOURCEDOCUMENTHEADER IN(
SELECT SDH.RECID FROM SOURCEDOCUMENTHEADER SDH
JOIN SQLDICTIONARY SD ON SD.TABLEID = SDH.SOURCERELATIONTYPE AND SD.FIELDID = 0 AND SD.SQLNAME IN('VENDINVOICEJOUR', 'CUSTINVOICEJOUR', 'PURCHREQTABLE')
JOIN ACCOUNTINGEVENT AE ON AE.SOURCEDOCUMENTHEADER = SDH.RECID AND AE.STATE = 3
WHERE SDH.ACCOUNTINGSTATUS = 1 AND NOT EXISTS
(SELECT TOP 1 SOURCEDOCUMENTHEADER FROM ACCOUNTINGEVENT WHERE ACCOUNTINGEVENT.SOURCEDOCUMENTHEADER = SDH.RECID AND ACCOUNTINGEVENT.STATE = 0)
GROUP BY SDH.RECID, SDH.ACCOUNTINGSTATUS, SDH.SOURCERELATIONTYPE, SDH.TYPEENUMNAME, SDH.TYPEENUMVALUE, SD.SQLNAME, AE.ACCOUNTINGDATE, AE.STATE, AE.RECID)
AND ACCOUNTINGSTATUS = 1
--Update SourceDocumentHeader table
UPDATE SOURCEDOCUMENTHEADER
SET ACCOUNTINGSTATUS = 2
WHERE RECID IN(
SELECT SDH.RECID FROM SOURCEDOCUMENTHEADER SDH
JOIN SQLDICTIONARY SD ON SD.TABLEID = SDH.SOURCERELATIONTYPE AND SD.FIELDID = 0 AND SD.SQLNAME IN('VENDINVOICEJOUR', 'CUSTINVOICEJOUR', 'PURCHREQTABLE')
JOIN ACCOUNTINGEVENT AE ON AE.SOURCEDOCUMENTHEADER = SDH.RECID AND AE.STATE = 3
WHERE SDH.ACCOUNTINGSTATUS = 1 AND NOT EXISTS
(SELECT TOP 1 SOURCEDOCUMENTHEADER FROM ACCOUNTINGEVENT WHERE ACCOUNTINGEVENT.SOURCEDOCUMENTHEADER = SDH.RECID AND ACCOUNTINGEVENT.STATE = 0)
GROUP BY SDH.RECID, SDH.ACCOUNTINGSTATUS, SDH.SOURCERELATIONTYPE, SDH.TYPEENUMNAME, SDH.TYPEENUMVALUE, SD.SQLNAME, AE.ACCOUNTINGDATE, AE.STATE, AE.RECID)