Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

AL Code for Using Period in Recurring Frequency of Recurring Journal

Posted on by 15,428
Hi Experts 
 
Has any developer here had a success to develop AL code that add Period (accounting period) option into Recurring Frequency of Recurring Journal? This way user can use period to line up frequency with their period. 
 
If yes and if you do not mind can you please share your code? 
 
Thanks 
Categories:
  • MahGah Profile Picture
    MahGah 15,428 on at
    AL Code for Using Period in Recurring Frequency of Recurring Journal
    Hi 
     
    We could not figure this out as standard way. We added new field that take this formula , then calculate the next posting date and add to next posting date
  • LA-13061059-0 Profile Picture
    LA-13061059-0 36 on at
    AL Code for Using Period in Recurring Frequency of Recurring Journal
    Hi MahGah
     
    Did you ever resolve this? We are in the same predicament during our project planning! 
     
    Having "Current Period" or CP-1, CP-12 etc. would be so useful.
  • MahGah Profile Picture
    MahGah 15,428 on at
    AL Code for Using Period in Recurring Frequency of Recurring Journal
    Hi Mr Bruvik 
     
    Thanks for your help. I have tried to use the code but I have no developer skill and just start learning that. Hence I failed 
     
    We use 4-4-5 which is something like below. As you can see it is not following any months or week. Like the first two periods are 4 weeks then the third is 5 weeks. Also every 6 years we have extra week to cover for all lost days :) but that is not important. 
     
    If code can use accounting period then all is set. 
     
    Thanks for your help here 
     
     
  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    AL Code for Using Period in Recurring Frequency of Recurring Journal
    Well with accounting periods not following the calendar months i see your struggle.
    I will try to set up the code you provided in a sandbox and see how it works and maybe that will give us some answers if no one else steps in here with a solution before I am able to finish that.
    Do you mind sharing how your accounting periods are set up for a complete fiscal year?
  • MahGah Profile Picture
    MahGah 15,428 on at
    AL Code for Using Period in Recurring Frequency of Recurring Journal
    Thanks Mr Bruvik 
     
    that is my struggle. Since we are not on month and we use 4-4-5 then I cannot use 4W or 5W (it is changing each month) I was hoping someone came up with development that let period uses in Recurring Frequency 
     
    I saw below code somewhere but that does not look correct. I mean it is for sure what I need but does not look accurate 
     
    tableextension 50100 MyRecurringFrequencyExt extends "Recurring General Journal Line"
    {
        fields
        {
            field(50100; "Recurring Frequency"; Option)
            {
                OptionMembers = D,W,M,Q,Y,P; // Add 'P' for Accounting Period
            }
        }
    }
     
     
    codeunit 50101 MyRecurringLogic
    {
        [EventSubscriber(ObjectType::Table, Database::"Recurring General Journal Line", 'OnAfterValidateEvent', 'Recurring Frequency', false, false)]
        local procedure HandleAccountingPeriodRecurringFrequency(var RecGenJournalLine: Record "Recurring General Journal Line")
        var
            AccountingPeriod: Record "Accounting Period";
        begin
            if RecGenJournalLine."Recurring Frequency" = RecGenJournalLine."Recurring Frequency"::P then begin
                // Fetch the accounting period and set the next posting date.
                AccountingPeriod.SetRange("Starting Date", RecGenJournalLine."Posting Date");
                if AccountingPeriod.FindFirst() then
                    RecGenJournalLine."Posting Date" := AccountingPeriod."Ending Date" + 1
                else
                    // Handle error or custom logic if accounting period is not found.
            end;
        end;
    }
     
  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    AL Code for Using Period in Recurring Frequency of Recurring Journal
    I do not think you can use the period directly in a date formula.
    You will have to figure out the end date for the next accounting period and use that date or use 1M if you have your accounting periods equal to one month.
     

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans