Wednesday, 15 September 2021

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.

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)

 


Tuesday, 14 September 2021

How to find D365FO application build version using X++ and compare with a constant ?

class checkBuildVersion

{   

     public static void main()

    {

        const str latestFixVersion = '10.1.209.0';

        boolean isLatest;

        str appBuildVersion =                                                                                                           Microsoft.Dynamics.BusinessPlatform.ProductInformation.Provider.ProductInfoProvider::get_Provider().ApplicationBuildVersion;

        if( checkBuildVersion::compareVersion(appBuildVersion, latestFixVersion) >=1)

        {

            //if latest version

        }

}


    public static int compareVersion(str _versionStr1, str _versionStr2)

    {

            int subVersion1;

            int subVersion2;

            str versionSeperator = '.';

            container con1 = str2con(_versionStr1, versionSeperator);

            container con2 = str2con(_versionStr2, versionSeperator);

            int maxLength = conLen(con1) > conLen(con2) ? conLen(con1) : conLen(con2);

            int counter = 1;

            for (counter = 1; counter <= maxLength; counter++)

            {

                subVersion1 = conPeek(con1, counter);

                subVersion2 = conPeek(con2, counter);

                if (subVersion1 > subVersion2)

                {

                    return 1;

                }

                else if (subVersion1 < subVersion2)

                {

                    return -1;

                }

            }

            return 0;

        }

}


Monday, 13 September 2021

System Security Duty V2 Entity shows/export stale data even after creating new roles and duties.

 Issue:

System Security Duty V2 (SystemSecurityDutyV2Entity) is showing same export even after creating new roles and duties

Resolution:

You need to batch SecurityRoleDutyPrivilegeExplodedGraphController class. At backend it will run a stored procedure that will refresh with new data. This batch will take very minimal time so admin can schedule the same as per business need.