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

Notifications

Announcements

No record found.

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 269
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
I have the same question (0)
  • Suggested answer
    Sankar Ramalingam Profile Picture
    262 on at
    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.
  • Ayushaman Profile Picture
    269 on at
     
    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > FastTrack for Dynamics 365

#1
Paresh Bhagwatwar Profile Picture

Paresh Bhagwatwar 11

#2
Priya_K Profile Picture

Priya_K 8

#3
CU25112007-0 Profile Picture

CU25112007-0 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans