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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to assign new Number Sequence (Voucher) based on Debit/Credit on LedgerJournalTrans

(0) ShareShare
ReportReport
Posted on by 6,478
Hello,
the requirement is that Voucher format on Vendor invoice journal should be according whether the line (LedgerJournalTrans) is a Debit or Credit.
For this, we have created new /Continious/ number sequence myCred for Credits and myDeb for debit lines.
myDeb is added to the Journal Names parameters as a /Voucher series/ field value and we have also added new field on Journal Names where we select the myCred num seq.
 
So.. now, when we create journal and go to Lines, journal lines is created automatically with the voucher based on myDeb. Let's say the value is myDeb-001. If we delete the line and create again the voucher number is still the same myDeb-001, which is correct.
Our desire is that, if we type a value in Credit field, Voucher number must be changed from myDeb to myCred.
For this I have created extension class of LedgerJournalTrans table and with CoC doing the below logic in modifiedField method. 
public void modifiedField(FieldId _fieldId)    {        next modifiedField(_fieldId);        LedgerJournalName journalName = LedgerJournalName::find(this.ledgerJournalTable().JournalName);        switch (_fieldId)        {            case fieldNum(LedgerJournalTrans, AmountCurCredit):                if (this.AmountCurCredit)                {                    ttsbegin;                    this.Voucher = NumberSeq::newGetVoucherFromCode(NumberSequenceTable::find(                        journalName.XXXNumberSequenceTableRefId).NumberSequence).voucher();                    ttscommit;                }            break;            case fieldNum(LedgerJournalTrans, AmountCurDebit):                if (this.AmountCurDebit)                {                    ttsbegin;                    this.Voucher = NumberSeq::newGetVoucherFromCode(NumberSequenceTable::find(                        journalName.NumberSequenceTable).NumberSequence).voucher();                    ttscommit;                }            break;        }    }
This is kinda working, but not really as desired, because it will generate new voucher number after each modification of value.
Goal is to get previously generated voucher number.
For example, if I change the Credit value to 1 and new Voucher number is generated as myCred-001 and then if I change Credit again it must not generate new Voucher (With the code above it will generate new myCred-002). Or if after I already changed the Credit value and then typed something in Debit and then again in Credit, it should not give me a new voucher and rather assign previously created number again.
 
I hope the goal is understandable :)
How can I achieve it?
Thanks.
 
I have the same question (0)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    300,702 Super User 2025 Season 2 on at
    How to assign new Number Sequence (Voucher) based on Debit/Credit on LedgerJournalTrans
    Hi vuivui,
     
    I never heard of this requirement before. Is this required for a particular country's regulation? (curiosity)
     
    To get the number available for selection again, ensure that you set up the number sequence to be continuous and also call the method NumberSeq::releaseNumber to get the unused number available in the status list of the number sequence.
     
  • Johnny Profile Picture
    6,478 on at
    How to assign new Number Sequence (Voucher) based on Debit/Credit on LedgerJournalTrans
    Hi Andre,
    Requirement came from our team from Germany, but I'm not sure the exact reason behind it.
     
    Is it necessary to have newly created number sequence in Parameters form?
  • André Arnaud de Calavon Profile Picture
    300,702 Super User 2025 Season 2 on at
    How to assign new Number Sequence (Voucher) based on Debit/Credit on LedgerJournalTrans
    Hi vuivui,
     
    I would suggest asking the purpose of the requirement. I have never seen this requirement in a German company.
     
    Where to have the setup for number sequences is not important. In case the number should be reused after changing from debit to credit or vice versa, check my previous comment about continuous and maintaining the number in a status list.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 776 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 606 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 402 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans