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

Pass any record as a parameter to procedure

(0) ShareShare
ReportReport
Posted on by

How can I create a method like Page.SetTableView(var Record: Record)?

It is possible to pass record of any table to this method.

Signature like 

procedure DoSomething(anyRec:Variant)
 is not suitable, becase in this case we can pass any type (Record, Integer, Date).

Example:

procedure DoSomethingWithRecords()
var
    c:Record Customer;
    i: Record Item;
begin
//...
    i.FindFirst();
   c.FindFirst();
//...
    DoSomething(i);  //ok
    DoSomething(c);  // ok
    DoSomething(1); // should not be possible to compile (rise AL0133)
end;


What signature should be correct for the method DoSomething in this case?

I have the same question (0)
  • Vaishnavi J Profile Picture
    3,094 on at

    Hi,

    You can write the above logic in this way.

    //Creating a procedure which takes two references.

    local procedure DoSomething(var Rec_Customer: Record Customer; var Rec_Item: Record Item)

       begin

           Message('The first customer name is %1', Rec_Customer.Name);

           Message('this first item name is %1', Rec_Item.Description);

       end;

    // How can you call the above procedure.

    1. You can call in using an action button click.

     action("Accept Order")
                    {
                        ApplicationArea = All;

                        trigger OnAction()
                        var
                            c: Record Customer;
                            i: Record Item;
                        begin

                            i.FindFirst();
                            c.FindFirst();
                            DoSomething(c, i); // You need to pass two refrences as you have created procedure which takes two value. if you want seperate procedure which does different things then create  a sperate procedure and take one record as parameter.
                        end;
                    }
    2. Or you can call using a field validation.
      field(SOStatus; rec.SOStatus)
                    {
                        ApplicationArea = All;
                        ToolTip = 'Sales Order Status';
                        Editable = true;

                        trigger OnValidate()
                        var
                            c: Record Customer;
                            i: Record Item;
                        begin
                            c.FindFirst();
                            i.FindFirst();
                            DoSomething(c, i);
                        end;
                    }
    3. Or you can call your procedure in some other procedure.
    procedure DoSomethingWithRecords()
    var
        c:Record Customer;
        i: Record Item;
    begin

        i.FindFirst();
        c.FindFirst();

        DoSomething(c, i)
    end;
    If my answer was helpful to you, please verify it so that other users know it worked. Thank you very much
  • Community Member Profile Picture
    on at

    Unfortuantely, this answer is absolutely unsuitable. You did not get the question at all.

    Firts of all, your method DoSomething uses 2 arguments what is already wrong.

    Second, you specified tables, what is also wrong. One method should be able to process any record (customer, item, company, whatever, etc). No one table must be specified.

    Check how the mentioned method works docs.microsoft.com/.../page-settableview-method.

    You can pass every record to it.

  • IB-29041624-0 Profile Picture
    1,187 Moderator on at

    If i understand your question correctly then i think the recordref datatype is what you are looking for.

    The recordref can be used to pass any record to a procedure

    docs.microsoft.com/.../recordref-data-type

  • Teddy Herryanto (That NAV Guy) Profile Picture
    14,306 Super User 2026 Season 1 on at

    Use RecordRef as your parameter. You can retrieve any tables using it.

  • Suggested answer
    YUN ZHU Profile Picture
    101,122 Super User 2026 Season 1 on at

    Hi, I know this might not be a great example, but hopefully it gives you some inspiration.

    [View:/cfs-file/__key/communityserver-discussions-components-files/758/0825.Test.mp4:822:617

    page 50100 MyPage
    {
        PageType = Card;
        ApplicationArea = All;
        UsageCategory = Administration;
    
        layout
        {
            area(Content)
            {
                group(GroupName)
                {
                    field(TableID; TableID)
                    {
                        ApplicationArea = All;
                        TableRelation = AllObjWithCaption."Object ID" where("Object Type" = filter('Table'));
                    }
                }
            }
        }
    
        actions
        {
            area(Processing)
            {
                action(ActionName)
                {
                    ApplicationArea = All;
    
                    trigger OnAction()
                    var
                        RecRef: RecordRef;
                    begin
                        RecRef.Open(TableID);
                        MyProcedure(RecRef);
                    end;
                }
            }
        }
    
        var
            TableID: Integer;
    
        local procedure MyProcedure(RecRef: RecordRef)
        var
            MyFieldRef: FieldRef;
        begin
            MyFieldRef := RecRef.Field(1);
            if RecRef.FindSet() then
                Message(MyFieldRef.Value);
        end;
    }

    Thanks.

    ZHU

  • Community Member Profile Picture
    on at

    Inge M. Bruvik, Teddy Herryanto

    Thanks for your answers, recordref is a helpfull workaround like a variant.

    But it is not the answer.

    To be honest I don't know why this question is so difficult. =(

    We already have the method "Page.SetRecord" in the core, but nobody can explain how it works.

    This method does not use variant or recordref, this method accepts any record and only record.

    Just look on this example:

    procedure Example()

       var

           somePage: Page "Customer Card";  

           rec1: Record Customer;

           rec2: Record Item;

           rec3: Record "Incoming Document";

       begin

           somePage.SetRecord(rec1);

           somePage.SetRecord(rec2);

           somePage.SetRecord(rec3);

       end;

    All three lines are correct. It does not require any specific table we can pass any.

    And this code will be successfully compiled.

  • IB-29041624-0 Profile Picture
    1,187 Moderator on at
    [quote user="kkrtsv"]

    Inge M. Bruvik, Teddy Herryanto

    Thanks for your answers, recordref is a helpfull workaround like a variant.

    But it is not the answer.

    To be honest I don't know why this question is so difficult. =(

    We already have the method "Page.SetRecord" in the core, but nobody can explain how it works.

    This method does not use variant or recordref, this method accepts any record and only record.

    Just look on this example:

    procedure Example()

       var

           somePage: Page "Customer Card";  

           rec1: Record Customer;

           rec2: Record Item;

           rec3: Record "Incoming Document";

       begin

           somePage.SetRecord(rec1);

           somePage.SetRecord(rec2);

           somePage.SetRecord(rec3);

       end;

    All three lines are correct. It does not require any specific table we can pass any.

    And this code will be successfully compiled.

    [/quote]

    The example you should does not accept any record. It only accept record of the type Customer with any filter applied to it. And that is no problem to get working as long as you know what record type you send.

    In the function you only have to declare t he record parameter as VAR.

     procedure customer (var customer: Record Customer)
        begin
           
        end;
    But if you do not know what kind of record you will pass to the function then you will have to use record ref.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,138 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,279 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,192

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans