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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

SetRange not working to get values from another record

(0) ShareShare
ReportReport
Posted on by 5

Hi , 

I am not able to get values from another table to compare with general ledger entries.

can you just tell me what i am missing ?

 trigger OnAction()
                var
                    Rec_GeneralLedgerEntry: Record "G/L Entry";
                    Rec_ExportTableEntry: Record CFS_EXPORTTABLENETRY;                             // it is buffer table which has few fields 
                    ExportExample: Codeunit CFS_ExportText;
               


                begin

                    Rec_GeneralLedgerEntry.SetRange("Document No.", Rec_ExportTableEntry."CFS_Document Number");                     // all values coming from Rec_ExportTableEntry are blank 
                    Rec_GeneralLedgerEntry.SetRange("Document Date", Rec_ExportTableEntry.CFS_DocumentDate);
                    Rec_GeneralLedgerEntry.SetRange("Posting Date", Rec_ExportTableEntry.CFS_PostingDate);

                    if Rec_GeneralLedgerEntry.FindFirst() then
                        ExportExample.ReCreateTextFile(Rec_GeneralLedgerEntry);                                                                                  //hence it created blank text file 


                end;
  • Suggested answer
    JAngle Profile Picture
    159 on at

    The text file is only created if it finds a value. Is it not a problem with the relating function?

  • Joshi Vaishnavi Profile Picture
    5 on at

    But why does the setrange is unable to get value even the value is present in Rec_ExportTableEntry?

  • Suggested answer
    THE Italian Profile Picture
    Microsoft Employee on at

    Change

    if Rec_GeneralLedgerEntry.FindFirst() then

                           ExportExample.ReCreateTextFile(Rec_GeneralLedgerEntry);    

    with

    if Rec_GeneralLedgerEntry.FindFirst() then

    message('there are entries')

    else

    message('no entries found');

    If there are no records found then it means

    a. No records in the table

    b. wrong filters applied

    You have to narrow down which are the queries that run server side (you might have a WHERE clause).

    That is the way to troubleshoot why it does not work.

    Use the debugger to see how the variable are popluated.

  • Suggested answer
    Anks27 Profile Picture
    1,087 on at

    Hello,

    I have gone through your code and question but not getting proper idea that what you want to do in this operation but as per my assumption, before you click on the action you have some data into CFS_EXPORTTABLENETRY table and you wanted to get the data by filtering from "G/L Entry", if my assumption is true then you must change the code as per below.

    • Definitely your exported file will be blank because before you Setrange the G/L Entry you must need to get the CFS_EXPORTTABLENETRY table.

    Code:

    trigger OnAction()

                    var

                        Rec_GeneralLedgerEntry: Record "G/L Entry";

                        Rec_ExportTableEntry: Record CFS_EXPORTTABLENETRY;                             // it is buffer table which has few fields 

                        ExportExample: Codeunit CFS_ExportText;

                    begin

        Rec_ExportTableEntry.Reset();

        if Rec_ExportTableEntry.FindFirst() then begin

        Rec_GeneralLedgerEntry.Reset();

                        Rec_GeneralLedgerEntry.SetRange("Document No.", Rec_ExportTableEntry."CFS_Document Number");

                        Rec_GeneralLedgerEntry.SetRange("Document Date", Rec_ExportTableEntry.CFS_DocumentDate);

                        Rec_GeneralLedgerEntry.SetRange("Posting Date", Rec_ExportTableEntry.CFS_PostingDate);

                        if Rec_GeneralLedgerEntry.FindFirst() then

                            ExportExample.ReCreateTextFile(Rec_GeneralLedgerEntry); 

                    end;

    Signed, Sealed and Delivered.

    Don't forget to help the community by Verifying the answer and Like it if your question has been answered. It will let others know that the topic has verified answer.

     

    Thanks & Regards,

    Ankit Shah(MCT-Microsoft Certified Trainer || Dynamics 365/Business Development Manager)

     

    Follow/Connect 101 on below

    LinkedIn:-   https://linkedin.com/in/dynamicpower101/

    Twitter:-     https://twitter.com/Dynamicpower101

    Facebook:- https://facebook.com/DynamicPower101/

    Telegram:- https://t.me/dynamicpower101

    Medium:-   https://medium.com/dynamicpower101

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 720 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 436 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 409 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans