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

Community site session details

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

Rec and xRec how to use

(0) ShareShare
ReportReport
Posted on by 70

I want to print the Instructor Name for the selected record when I open the page.
And I have those two system variables Rec and xRec, that seems work the same way.
I was reading stuff, but the only useful info I found was this https://www.oreilly.com/library/view/programming-microsoft-dynamics/9781786468192/35ee3208-3f84-40b0-931e-bb438b49a1eb.xhtml

The page says "Rec represents the current record data in process and xRec represents the record data before it was modified."
That is simple to understand, but it's just too vague for me to comprehend .

In the first and third  piece of code I have the same result each time.
In the second piece, I got a different result according the one I'm clicking.

If isn't asking too much, I would like for someone to explain why those results are happening, which one should I use in similar attempts 
and if possible, very simple examples of both

I'm a NAV starter, I came from a C# background so OOP explanations can also help

PS: The FINDFIRST isn't important (I think it's not perfectly used,) I just put there because  I don't know yet a way to know if there's records, so I figured out that if there's record there's at least one record FINDFIRST would work

OnOpenPage()

IF Rec.FINDFIRST = TRUE THEN 
BEGIN


MESSAGE(FORMAT(Rec."Instructor Name"));
END
ELSE




OnOpenPage()


IF xRec.FINDFIRST = TRUE THEN 
BEGIN


MESSAGE(FORMAT(Rec."Instructor Name"));
END
ELSE

// or 

IF xRec.FINDFIRST = TRUE THEN 
  BEGIN
    //texto:= Rec.GETFILTER("Formation Code");
    
    MESSAGE(FORMAT(xRec."Instructor Name"));
    END
    ELSE 

I have the same question (0)
  • Nitin Verma Profile Picture
    21,684 Moderator on at
    RE: Rec and xRec how to use

    One Quick questions:

    1. Is this list page or Card page?

  • Belarmino Vicenzo Profile Picture
    70 on at
    RE: Rec and xRec how to use
    [quote user="Nitin Verma"]

    One Quick questions:

    1. Is this list page or Card page?

    [/quote]

    It's a List page, but the message is showing on opening the Card page

  • Suggested answer
    Nitin Verma Profile Picture
    21,684 Moderator on at
    RE: Rec and xRec how to use

    Ok

    IF FINDFIRST THEN

     MESSAGE('%1',"Instructor Name");

    It will display FIRST RECORD name.

  • Belarmino Vicenzo Profile Picture
    70 on at
    RE: Rec and xRec how to use
    [quote user="Nitin Verma"]

    Ok

    IF FINDFIRST THEN

     MESSAGE('%1',"Instructor Name");

    It will display FIRST RECORD name.

    [/quote]


    What does this code MESSAGE('%1',"Instructor Name"); means 

    I don't need to get the first value or other value, bro. That's just a simple code that I wrote to use Rec and xRec
    Just that, I know what happens, but I don't know why
    I want to know why my two similar codes work different, I want an explanation about my code, how /when to use Rec and xRec.



  • Suggested answer
    Nitin Verma Profile Picture
    21,684 Moderator on at
    RE: Rec and xRec how to use

    Rec represents the current record data in process and xRec represents the record data before it was modified.

    So use always Rec.Findfirst until you require your last value (before modification)

    Cheers!

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,327

#2
Sumit Singh Profile Picture

Sumit Singh 2,734

#3
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,599

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans