Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
FastTrack for Dynamics 365 forum
Suggested answer

Invoice journal financial dimension update and service accounting code issue

(5) ShareShare
ReportReport
Posted on by 203
Hi Everyone ,
 

I am working on the Invoice Journal form, where clicking the Debit Note button successfully creates a Ledger Journal Transaction in LedgerJournalTrans. The LedgerDimension is set correctly using the getLedgerDim method, and the transaction is recorded under the Vendor account. However, the Business Unit and Vendor financial dimensions are not updating in LedgerJournalTransDimension.I also want to update service accounting code under  taxinformation menu it would be very helpful if you have some idea about how can i do it. Beside if you have any suggestion about my code snippet i will be very happy to listen and improve .

The getLedgerDim method is already used to derive the ledger dimension, but it seems that LedgerJournalTransDimension is not being explicitly updated. How can I ensure that the Business Unit and Vendor dimensions are properly assigned when creating the ledger transaction? Should I explicitly insert/update LedgerJournalTransDimension, or is there another recommended approach to fix this issue?
 

NOTE: I removed some fields to keep the snippet meaningful and smaller those are working fine and i think it has no relation with my question .
service accounting code and financial dimension remains blank  i was talking about ss for reference:

  [Control("Button")]
    class DebitNoteBtn
    {
    public void clicked()
    {
      super();
      FormButtonControl generateButton = element.control(element.controlId(formControlStr(AcxBulkTagDestroy, btnGenerate))) as FormButtonControl;

      AcxBulkTagDestroyDetail acxBulkTagDestroyDetailSel;
      LedgerJournalTable ledgerJournalTable;
      InventItemGroupItem inventItemGroupItem;
      LedgerJournalTrans ledgerJournalTransVendInvoice;
      RecId offsetLedgerDimension;

      str journalId, vendorAccountNum, businessUnit;
      real makingCharges, grossWeightSum, otherChargesSum;
      ItemId itemId;
      MainAccountNum offsetAccountNum = 'xxxxxxxx'; 
      container conOffsetValues;

      
      vendorAccountNum = AcxBulkTagDestroy_AccountId.text();
      businessUnit = AcxBulkTagDestroy.InventSiteId;


      if (vendorAccountNum == "")
      {
        error("Vendor Account Number cannot be blank");
        AcxBulkTagDestroy_ds.refresh();
        return;
      }

     
      acxBulkTagDestroyDetailSel = AcxBulkTagDestroyDetail_DS.cursor();
      if (!acxBulkTagDestroyDetailSel)
      {
        error("No detail record selected");
        return;
      }

      select sum(OtherChargesAmount), sum(GrossWeight), ItemId from acxBulkTagDestroyDetailSel
            where acxBulkTagDestroyDetailSel.BulkTagDestroyNo == AcxBulkTagDestroy.BulkTagDestroyNo;
      otherChargesSum = acxBulkTagDestroyDetailSel.OtherChargesAmount;
      grossWeightSum = acxBulkTagDestroyDetailSel.GrossWeight;

      select firstOnly acxBulkTagDestroyDetailSel
    join inventItemGroupItem
        where acxBulkTagDestroyDetailSel.BulkTagDestroyNo == AcxBulkTagDestroy.BulkTagDestroyNo
        && inventItemGroupItem.ItemId == acxBulkTagDestroyDetailSel.ItemId;


      itemId = inventItemGroupItem.ItemGroupId;

   
      if (AcxBulkTagDestroy.JournalNum)
      {
        error("Debit note is already generated for this entry.");
        return;
      }

      
      ttsBegin;
      try
      {
        
        ledgerJournalTable.JournalName = 'DBS/ADR/22';
        ledgerJournalTable.Name = "Debit Note-22";
        ledgerJournalTable.initValue();
        ledgerJournalTable.insert();

      
        journalId = ledgerJournalTable.JournalNum;

        ledgerJournalTransVendInvoice.initValue();
        ledgerJournalTransVendInvoice.JournalNum = journalId;
        ledgerJournalTransVendInvoice.Voucher =NumberSeq::newGetNum(LedgerParameters::numRefLedgerTempVoucher()).num();
        ledgerJournalTransVendInvoice.LedgerDimension = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(vendorAccountNum, LedgerJournalACType::Vend);
        ledgerJournalTransVendInvoice.AccountType = LedgerJournalACType::Vend;
        ledgerJournalTransVendInvoice.OffsetAccountType = LedgerJournalACType::Ledger;
        ledgerJournalTransVendInvoice.Payment = '100% Advance';
        ledgerJournalTransVendInvoice.TransactionType = LedgerTransType::Vend;
 
        conOffsetValues += businessUnit;
        conOffsetValues += itemId;
        conOffsetValues += vendorAccountNum;
		
        offsetLedgerDimension = this.getLedgerDim(offsetAccountNum, vendorAccountNum, businessUnit, itemId);
        ledgerJournalTransVendInvoice.OffsetLedgerDimension = offsetLedgerDimension;
        ledgerJournalTransVendInvoice.insert();
        AcxBulkTagDestroy.JournalNum = journalId;

        generateButton.enabled(true);
        AcxBulkTagDestroy_AccountId.enabled(false);
        AcxBulkTagDestroy_ds.research(true);

        
        ttsCommit;
      }
      catch (Exception::Error)
      {
        ttsAbort;
        error("Error occurred during journal creation or data insertion. Please try again.");
      }
    }

    public int64 getLedgerDim(MainAccountNum _mainAccountNum, str _vendorAccountNum, str _businessUnit, str _itemId)
    {
      
      LedgerAccountContract ledgerAccountContract = new LedgerAccountContract();
      DimensionAttributeValueContract dimensionAttributeValueContract;
      List valueContracts = new List(Types::Class);

      MainAccount mainAccount = MainAccount::findByMainAccountId(_mainAccountNum);
      ledgerAccountContract.parmMainAccount(mainAccount.MainAccountId);

      dimensionAttributeValueContract = DimensionAttributeValueContract::construct('BusinessUnit', _businessUnit);
      valueContracts.addEnd(dimensionAttributeValueContract);

     
      dimensionAttributeValueContract = DimensionAttributeValueContract::construct('ItemGroup', _itemId);
      valueContracts.addEnd(dimensionAttributeValueContract);

      dimensionAttributeValueContract = DimensionAttributeValueContract::construct('Vendor', _vendorAccountNum);
      valueContracts.addEnd(dimensionAttributeValueContract);

   
      ledgerAccountContract.parmValues(valueContracts);

      DimensionStorage dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(ledgerAccountContract);
      DimensionAttributeValueCombination dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
      return dimensionAttributeValueCombination.RecId;
    }

    }
I tried to be very brief about my requirement if you have some queries feel free to ask it out.

Thanks for the assistance,
Ayushaman
  • Ayushaman Profile Picture
    203 on at
    Invoice journal financial dimension update and service accounting code issue
     
    Thanks for your insights!
    As suggested by you i created default dimension and my vendor and buisness unit starts appearing perfectly fine.
    For the second suggestion for service accounting code  the values are not updating properly i think i might be doing something wrong or missing something the below is my code snippet.
            ledgerJournalTransVendInvoice.OffsetLedgerDimension = offsetLedgerDimension;
    
            ledgerJournalTransVendInvoice.insert();
    
            TransTaxInformation transTaxInfo =
            TransTaxInformationHelper::findOrCreateTransTaxInformationByRecord(ledgerJournalTransVendInvoice);
    
            if (transTaxInfo)
            {
              //transTaxInfo.selectForUpdate(true);
              transTaxInfo.ServiceCode = 4587; 
             // transTaxInfo.update();
            }
           
            AcxBulkTagDestroy.JournalNum = journalId;
    
            generateButton.enabled(true);
            AcxBulkTagDestroy_AccountId.enabled(false);
            AcxBulkTagDestroy_ds.research(true);
    
            
            ttsCommit;
    Thanks,
    Ayushaman
  • Suggested answer
    Sankar Ramalingam Profile Picture
    236 on at
    Invoice journal financial dimension update and service accounting code issue
    1. For Account  financial dimension, you need to populate the value in field LedgerJournalTrans.DefaultDimension. you may look at this blog (https://community.dynamics.com/blogs/post/?postid=e42a4b2d-50d0-42a9-852a-381283d37b96) to generate DefaultDimension from actual dimension values.
     
    2. Tax information is in separate table, take a look at TransTaxInformationHelper::findOrCreateTransTaxInformationByRecord(LedgerJournalTrans) to update the "Service accounting codes" once LedgerJournalTrans is inserted.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,663 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,672 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans