Skip to main content

Notifications

Announcements

No record found.

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

Re: Cash Receipt Journal: Using SetRange for dynamic Journal Template Name.

(1) ShareShare
ReportReport
Posted on by 4
Hi,
I have used SetRange in the Cash Receipt Journal for the Journal Template Name. I need to know how to set a dynamic SetRange for the Journal Template Name. Below is the code I have used
 
Note:  GenJournalBatch.SetRange("Journal Template Name", 'CASHRECEPT');
'CASHRECEPT' _ I need this name to have a dynamic value
For Exapmle;
trigger OnLookup(var Text: Text): Boolean
                    var
                        GenJournalBatch: Record "Gen. Journal Batch";
                         begin
                        GenJournalBatch.Reset();
                        GenJournalBatch.SetRange("Journal Template Name", 'CASHRECEPT');
                        if PAGE.RunModal(Page::"General Journal Batches", GenJournalBatch) = ACTION::LookupOK then begin
                            Rec."Batch ID" := GenJournalBatch.Name;
                        end;
                    end;

 
Thank You ,
 
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 74,115 Super User 2024 Season 2 on at
    Re: Cash Receipt Journal: Using SetRange for dynamic Journal Template Name.
    This requirement looks the same as the Batches button on the General Journal Template, which will open the Batches corresponding to the Journal Template Name.
    Hope this can give you some hints.
     
    Thanks.
    ZHU
  • Suggested answer
    Yi Yong Profile Picture
    Yi Yong 1,470 Super User 2024 Season 2 on at
    Re: Cash Receipt Journal: Using SetRange for dynamic Journal Template Name.
    Hello,
     
    You can create a var text and then GenJournalBatch.SetRange("Journal Template Name", TextVar);
  • Suggested answer
    Saif Ali Sabri Profile Picture
    Saif Ali Sabri 370 on at
    Re: Cash Receipt Journal: Using SetRange for dynamic Journal Template Name.

    My response was crafted with AI assistance, tailored to provide detailed and actionable guidance for your query.

    To make the SetRange value for the "Journal Template Name" dynamic, you can replace the hardcoded value 'CASHRECEPT' with a variable. This allows you to pass the dynamic value to the SetRange at runtime. Here's how you can modify your code:

    Modified Code:

    al  
    trigger OnLookup(var Text: Text): Boolean
    var
    GenJournalBatch: Record "Gen. Journal Batch";
    JournalTemplateName: Text; // Define a variable to hold the dynamic template name
    begin
    // Set the dynamic value for JournalTemplateName
    JournalTemplateName := 'CASHRECEPT'; // Replace this with logic to assign the dynamic value

    GenJournalBatch.Reset();
    GenJournalBatch.SetRange("Journal Template Name", JournalTemplateName); // Use the variable here

    if PAGE.RunModal(Page::"General Journal Batches", GenJournalBatch) = ACTION::LookupOK then begin
    Rec."Batch ID" := GenJournalBatch.Name;
    end;
    end;

    Explanation:

    1. Dynamic Value: The JournalTemplateName variable is introduced to store the dynamic value for the journal template name.

      • You can assign this variable any value based on your application's context, such as user input, a configuration record, or another field in your page.
    2. SetRange with Variable: Instead of hardcoding 'CASHRECEPT', the variable JournalTemplateName is passed to the SetRange method. This allows you to dynamically filter the records based on runtime conditions.

    3. Logic for Dynamic Value: Replace the JournalTemplateName := 'CASHRECEPT'; line with your logic to determine the dynamic value for the journal template name, for example:

      • Retrieve the value from a field in the current record.
      • Fetch the value from a setup table or user preferences.

    Example for Dynamic Assignment:

    If the value is based on a setup table, you can do something like this:

    al  
    var
    GeneralJournalSetup: Record "General Journal Setup";
    begin
    if GeneralJournalSetup.Get() then
    JournalTemplateName := GeneralJournalSetup."Default Journal Template Name"
    else
    Error('General Journal Setup is not configured.');
    end;

    By making the JournalTemplateName dynamic, the code becomes flexible and reusable for different scenarios.

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans