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 :
Small and medium business | Business Central, N...
Answered

strange Setrange

(0) ShareShare
ReportReport
Posted on by 238

table 52002 "NYT Best Sellers"
{
    Caption = 'Best Sellers Book';
    DataClassification = CustomerContent;

    fields
    {
        field(10; "List Name"; Text[250])
        {
            Caption = 'List Name';
            DataClassification = CustomerContent;
        }
        field(20; "Line No."; BigInteger)
        {
            Caption = 'Line No.';
            DataClassification = CustomerContent;
        }
        field(30; "Book Title"; Text[250])
        {
            Caption = 'Book Title';
            DataClassification = CustomerContent;
        }
        field(40; "Book Description"; Text[2048])
        {
            Caption = 'Book Description';
            DataClassification = CustomerContent;
        }
        field(50; "Book Author"; Text[250])
        {
            Caption = 'Book Author';
            DataClassification = CustomerContent;
        }
        field(60; "Amazon URL"; Text[250])
        {
            Caption = 'Amazon URL';
            DataClassification = CustomerContent;
            ExtendedDatatype = URL;
        }
    }
    keys
    {
        key(PK; "List Name", "Line No.")
        {
            Clustered = true;
        }
    }
    trigger OnInsert()
    begin
        "Line No." := GetNextLineNo();
    end;

    procedure GetNextLineNo(): BigInteger
    var
        NYTBestSellers: Record "NYT Best Sellers";
    begin
        NYTBestSellers.SetRange("List Name", "List Name");
        if NYTBestSellers.FindLast() then
            exit(NYTBestSellers."Line No."   1);
        exit(1);
    end;
}

here setrange applied on same table and with same filed .Generally we use setrange to field data from two table with one field from table 1 and other filed from table 2 then we get mating value then we perform any operation like findfirst or findset and do operation on fields 

but what is purpose of setrange on same table with same field ?

may be answer is easy but i don't know answer please experts can you guide me on this 

thanks in advance....

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    The purpose here is to get a set of records from the NYT Best Sellers table with the same "List Name" that is just inserted.

    To make the code more readable i think it should be changed to:

    NYTBestSeller.SetRange("List Name",rec."List Name");

    Then it would be clearer that you actually set a filter on the list name with the value for the record that is just inserted since the GetNextLineNo is called from the OnInsert trigger.

    I hope this made sense.

  • Verified answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at

    Hi, NYTBestSellers."List Name" and "List Name" are the same field, but not in a same variable.

    As Inge M. Bruvik said, the latter "List Name" should be Rec."List Name", The purpose of these codes are to find last "Line No." in "NYT Best Sellers" table which "List Name" is same as opening record.

    Hope this will help.

    Thanks.

    ZHU

  • DineshM Profile Picture
    238 on at

    Hello

    what I understand here two parameter in setrange  actually but one from same table .one is record variable which provide independent  Record NYT Best Sellers table and one is Rec. Listname from same table.

    when oninsert trigger invoke by inserting value in listname it will check in Record variable filed list name and then if last line match then it will increment line no by 1

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    The first parameter is the field name you want to set range on and the second one is the value you want to set the range on.

    Setrange is basically just another way for adding a filter.

    So

    setfilter(Fieldname,filtervalue);

    would have the same effect.

    But your conclusion is correct. Line number is increased by 1.

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,226

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,047 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,257 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans