How to: Update 1 financial dimension of ledger dimension in D365FO in X++

 I received a request to update the cost center financial dimension for the posted GL transactions for the fixed asset depreciation journal. There was an issue with master data, and the default financial dimensions were corrected after the journal was posted.  Below is the job that I created to update the FD on the Ledger dimension using the default dimension


public static void main(Args _args)

    {

        GeneralJournalAccountEntry          GeneralJournalAccountEntryUpd;

        GeneralJournalEntry                 GeneralJournalEntryUpd;

        AssetTrans                          assetTrans;

        AssetBook                           assetBook;

        DimensionAttribute                  dimAttr;

        DimensionAttributeValueSetStorage   defaultDimStorage;

        DimensionAttributeValue             dimAttrValue;

        DimensionAttributeValueSetStorage   newDimStorage;

        RecId                               newDimSetRecId;

        RecId                               mergedLedgerDim;

        str                                 dimValue;

        ttsBegin;

        while select forUpdate GeneralJournalAccountEntryUpd

            where  (GeneralJournalAccountEntryUpd.PostingType == LedgerPostingType::LedgerJournal)

            join GeneralJournalEntryUpd

            where GeneralJournalEntryUpd.RecId          ==  GeneralJournalAccountEntryUpd.GeneralJournalEntry

&& GeneralJournalEntryUpd.SubledgerVoucherDataAreaId == "US01"

&&  GeneralJournalEntryUpd.SubledgerVoucher like "DPL-00*"

        {

            select firstonly assetTrans where assetTrans.Voucher == GeneralJournalEntryUpd.SubledgerVoucher && assetTrans.DataAreaId == GeneralJournalEntryUpd.SubledgerVoucherDataAreaId;

            select firstonly assetBook where assetBook.AssetId == assetTrans.AssetId  && assetBook.DataAreaId == GeneralJournalEntryUpd.SubledgerVoucherDataAreaId ;

            dimAttr = DimensionAttribute::findByName('CostCenter');

            defaultDimStorage = DimensionAttributeValueSetStorage::find(assetBook.DefaultDimension);

            dimValue = defaultDimStorage.getDisplayValueByDimensionAttribute(dimAttr.Recid);

            dimAttrValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttr, dimValue, false, true);

            newDimStorage = new DimensionAttributeValueSetStorage();

            newDimStorage.addItem(dimAttrValue);

            newDimSetRecId = newDimStorage.save();

            mergedLedgerDim = LedgerDimensionFacade::serviceCreateLedgerDimForDefaultDim(newDimSetRecId,GeneralJournalAccountEntryUpd.LedgerDimension);

            GeneralJournalAccountEntryUpd.LedgerDimension = mergedLedgerDim;

            GeneralJournalAccountEntryUpd.LedgerAccount   = DimensionAttributeValueCombination::find(GeneralJournalAccountEntryUpd.LedgerDimension).DisplayValue;

            GeneralJournalAccountEntryUpd.MainAccount   = DimensionAttributeValueCombination::find(GeneralJournalAccountEntryUpd.LedgerDimension).MainAccount;

            GeneralJournalAccountEntryUpd.DoUpdate();

            info(strFmt("%1",GeneralJournalAccountEntryUpd.RecId));

        }

        ttscommit;

    }

Hope this helps someone.



Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. I would like to understand whether it is technically possible to update a value in the GeneralJournalAccountEntry table through custom X++ code using doUpdate() without any access restricted error thrown

    Microsoft documentation states:
    "Dynamics 365 Finance defines the books of accounts as the official accounting entries that are created and posted to the general ledger. The accounting entries are stored in the GeneralJournalEntry and GeneralJournalAccountEntry tables, together with their related references. The transaction records contain date, amount, text, creation date, and created-by fields. An accounting entry can be corrected only by adding new reversing and correcting entries, not by changing the existing records. Dynamics 365 Finance doesn't provide any way for users to alter these records."

    Based on the above statement, my understanding is that users cannot modify these records through standard application functionality. However, is it still possible for a developer to update records in the GeneralJournalAccountEntry table directly using custom X++ code or other backend methods (I'm a system admin) without throwing an access resticted erroe thrown.

    Additionally, if a record is updated directly in the backend and Database Logging has not been configured for this table, would there be any audit trail or logging available to identify that the record was modified, including details such as who made the change and when it was changed?

    I would appreciate your help in clarifying this.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to: Get ledger dimension from string in D 365 FOE

How to: Use enum values instead of integers in BI reports for Dynamics 365 finance and operations

How to: Import Bank statements from Azure file storage to Dynamics 365 finance and operation using Power automate (formally flow)