Skip to main content

Notifications

Announcements

No record found.

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

How can I Learn - How to use Get method ,setrange(), setfilter(),and other basic methods in AL

(0) ShareShare
ReportReport
Posted on by 35

How can I Learn - How to use Get method ,setrange(),  setfilter(),and other basic methods in AL 

I am really excited to learn this language, so can please refer some methods to learn this language , microsoft learn is bit confusing for me so any other resources 

can you people suggest it will be a great help!!

Thanks in advance.

  • Suggested answer
    How can I Learn - How to use Get method ,setrange(), setfilter(),and other basic methods in AL
  • How can I Learn - How to use Get method ,setrange(), setfilter(),and other basic methods in AL
    The use of Setter and Getter is necessary in controlling important properties that are often used and require exact values. For example, the age attribute stores a person's age. In reality, the age range is from 0 to 100, so we cannot let the program store a negative age value or more than 100. 
  • How can I Learn - How to use Get method ,setrange(), setfilter(),and other basic methods in AL
    To use the GET method, SETRANGE(), SETFILTER(), and other basic methods in AL, you can follow these steps:
    Create a new codeunit or add code to an existing one where you want to use these methods.
    Declare variables to hold the data you want to retrieve or modify using these methods. For example:
    VAR
      Record: RecordName;
      Text: Text[50];
      Integer: Integer;

    Use the GET method to retrieve a record by its primary key or any other field. For example: 
    Record.GET(PrimaryKeyValue);
    Record.GET("Field Name", FieldValue);
     
    Use the SETRANGE() method to filter records based on specific criteria. For example:
    Record.SETRANGE("Field Name", FilterValue);
    Record.SETRANGE("Field Name", FilterValue1, FilterValue2);
     
    Use the SETFILTER() method to filter records based on complex criteria using operators like '=', '<>', '>', '<', '<=', '>=', etc. For example:
    Record.SETFILTER("Field Name", '[Operator]', FilterValue);
     
    Use other basic methods like FINDSET(), FINDFIRST(), FINDLAST(), NEXT(), etc., to navigate through the filtered records or perform operations on them. For example:
    IF Record.FINDSET THEN BEGIN
      // Handle the found records
      ...
    }
    Record.FINDFIRST;
    WHILE Record.NEXT DO BEGIN
      // Handle each record
      ...
    }
     
    Use additional methods like INSERT, MODIFY, DELETE, or MODIFYALL to modify the retrieved records as per your business logic. For example:
    Record.DELETE;
    Record.MODIFY;
    Record.MODIFYALL(FieldToUpdate, NewValue);
    These are some of the basic methods you can use in AL to work with records and data in Dynamics 365 Business Central. Modify them as per your specific requirements.
  • Suggested answer
    Steven Renders Profile Picture
    Steven Renders 5,053 Super User 2024 Season 1 on at
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 76,009 Super User 2024 Season 2 on at
    RE: How can I Learn - How to use Get method ,setrange(), setfilter(),and other basic methods in AL

    Hi, 

    Get method: retrieves one record based on values of the primary key fields.

    setrange(),  setfilter(): Assigns a filter to a field that you specify. Basically the same, but setfilter can take parameters.

    For example, 

    DimensionValue.SetFilter("Dimension Id", '<>%1', BlankGuid);

    Then I don't remember which expert's blog I downloaded the picture below, but it has always been useful. Hope that gives you some hints too.

    pastedimage1669594129231v1.png

    Thanks.

    ZHU

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,274 Super User 2024 Season 1 on at
    RE: How can I Learn - How to use Get method ,setrange(), setfilter(),and other basic methods in AL

    Hi

    the concept is very simple

    the setrange and setfilter applied to a table instance in AL return a set of data that you can cycle through... e.g. REPEAT UNTIL

    the get, on the other hand, is nothing more than a quick pointer using the primary key of the table to position you on the desired record. Be careful that when you use GET you are not returning a data set, so you cannot apply a loop otherwise your code will scroll through the table records from your selected record to the end

    www.youtube.com/watch

    DANIELE

  • Suggested answer
    Amit_Sharma Profile Picture
    Amit_Sharma 2,545 on at
    RE: How can I Learn - How to use Get method ,setrange(), setfilter(),and other basic methods in AL

    Hi,

    Refer the below link

    https://erpconsultors.com/use-of-setrange-and-setfilter-in-dynamics-365/

    For more learning visit www.erpconsultors.com

    Regards
    Amit Sharma
    www.erpconsultors.com
    Press Yes if Info is useful

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,488 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans