Rec and xRec same when updating through RECORDREF

robertderoosrobertderoos Member Posts: 10
I have a simple function :) which applies a change to a field in the sales line to other sales lines using RECORDREF and FIELDREF.
ChangeSublineField(NewRec : Record "Sales Line";FieldNo : Integer)
  SetTargetRange(UpdateRec,NewRec);
  RecRefNewRec.GETTABLE(NewRec);
  FieldRefNewRec := RecRefNewRec.FIELD(FieldNo);

  IF UpdateRec.FINDSET THEN REPEAT
    RecRefUpdateRec.GETTABLE(UpdateRec);
    FieldRefUpdateRec := RecRefUpdateRec.FIELD(FieldNo);
    FieldRefUpdateRec.VALIDATE(FieldRefNewRec.VALUE);
    // RecRefUpdateRec.MODIFY(TRUE);
    RecRefUpdateRec.SETTABLE(UpdateRec);
    UpdateRec.MODIFY(TRUE);
  UNTIL UpdateRec.NEXT = 0;
In the OnModify trigger of Sales Line there is code which compares Rec values with xRec values in order to notice a change.
When updating through my function no changes are detected and through debugging I found out that Rec and xRec are the same (both with the updated value).
It makes no difference [-X if I modify through RecRefUpdateRec.MODIFY(TRUE) or through UpdateRec.MODIFY(TRUE).

I can add the code from the OnModify trigger to the function but then every time someone changes the code in the OnModify trigger he or she must do this also in this function. This mean more documentation, etc., etc.

Does anyone has a solution for this problem.
I'm developing in 5.0, is it a bug? :bug:

Thanks,
Robert

Comments

  • ajhvdbajhvdb Member Posts: 672
    Rec and xRec are not always the same in NAV 4.02 too. Doesn't matter if you use recref or not.

    In you situation:
    Are you sure NewRec and others are defined as var?
  • krikikriki Member, Moderator Posts: 9,094
    What I am used to find is that if you do a MODIFY on a record-variable, both rec and Xrec have the same value. They only have a different value if the modify is launched by a form-SourceTable-record.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • robertderoosrobertderoos Member Posts: 10
    Thank you for your replies.

    I never knew this, so this could have some serious consequences. :cry:
    I think :-k we have to move some code to field validation or update functions , like UpdateUnitPrice or UpdateDates.
  • krikikriki Member, Moderator Posts: 9,094
    You can also put some code in a function that accepts 2 records : the new and the old.
    In your program, you can run this function yourself with an old version of the record and the version on which you are working. So you need to variables to do this.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ajhvdbajhvdb Member Posts: 672
    kriki wrote:
    What I am used to find is that if you do a MODIFY on a record-variable, both rec and Xrec have the same value. They only have a different value if the modify is launched by a form-SourceTable-record.

    Correct, and onmodify from header to lines (salesline, etc.) don't always work.
Sign In or Register to comment.