web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :

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

vinitgoyal2005 Profile Picture vinitgoyal2005 6,332

 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.




This was originally posted here.

Comments

*This post is locked for comments