[solved]Easy question on xRec

massimopasqualimassimopasquali Member Posts: 82
edited 2016-11-08 in NAV Three Tier
Hello boys,

I have alway a little mistake : you considerate xRec the result of previous istruction or the previours record before the update?

For example :

IF "No." <> xRec."No." THEN BEGIN
....

How do you interpreter that? Previous record or previous istruction?

Answers

  • DenSterDenSter Member Posts: 8,307
    technically xrec is the record that is currently in the database, and rec is what it is being changed to. So if you change the Name of a customer, let's say "ACME" is the name now, and you want to change it to "ACME, Inc.", then the "IF Name <> xRec.Name" statement would be in the OnValidate of the Name field. This trigger is executed as soon as you leave the field, but before the new value is written to the database, so it is technically not a record yet.

    Basically, the "IF rec.Field <> xrec.field" statement means "if the field value has changed", and you would normally use this in the field validation code. I've also used "IF rec.field = xrec.field THEN EXIT;", and this means "if the field has not changed then skip the validation logic"
  • massimopasqualimassimopasquali Member Posts: 82
    grazie
  • SavatageSavatage Member Posts: 7,142
    We use it on the item description field like this..
    IF (Rec.Description <> xRec.Description) THEN
    IF NOT CONFIRM('Do you want to change the value from "%1" to "%2" in field "%3"?',FALSE,
    xRec.Description,Rec.Description,FIELDCAPTION(Description)) THEN
    ERROR('Press ESC to exit the field');
    END;
    

    Sometimes users type in the field and accidentally change it, so at least they have to confirm the change instead of it happening automatically by mistake.
Sign In or Register to comment.