OnModify trigger

ntnt Member Posts: 160
hi all,

can i change a record and skip the OnModify trigger?

thanks.

Comments

  • krikikriki Member, Moderator Posts: 9,086
    Yes, you can use MODIFY(FALSE); instead of MODIFY(TRUE);

    If you want to do it in a form, you need to put some code in the "Form - OnModifyRecord()"-trigger:
    MODIFY(FALSE); // you write the record yourself, without using the triggers
    EXIT(FALSE); // you tell Navision NOT to modify the record (you just did it yourself)
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ntnt Member Posts: 160
    thanks :D
  • ntnt Member Posts: 160
    can i do that just for one field?
  • krikikriki Member, Moderator Posts: 9,086
    nt wrote:
    can i do that just for one field?
    What do you mean with this?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • kinekine Member Posts: 12,562
    No, because what you want to do if you change two fields and after that you will "save" the record? (by moving to another...)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,304
    The OnModify trigger fires off when a modified record is written to the database, not for individual fields.
  • ntnt Member Posts: 160
    i want only save the record if i change a fied a particulary field. all the other i dont want permit to change.
  • David_CoxDavid_Cox Member Posts: 509
    Check the Rec.MyField value against the xrec.MyField value in the on modify trigger, if the code is in a code unit then there is no xrec so store the original record and compare the field to the changed record.

    OnModify()
    // Test the primary key fields match and if changed
    IF (rec."No." <> xrec."No.") OR (rec.MyField = xrec.MyField)THEN
    EXIT;

    Why not just create a limited entry new form for the users you want to lock out of changing these fields, make this the default and the original form run from setup?
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: [email protected]
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • DenSterDenSter Member Posts: 8,304
    Which still saves the record, it just skips the rest of the OnModify code. If you want to prevent the record from being saved, you do ERROR instead of EXIT.
  • ntnt Member Posts: 160
    in that way all the editable fields can be modify.
  • David_CoxDavid_Cox Member Posts: 509
    Ok then on after get record, store the record in a variable, on modify check the field against the variable, if the field has changed update and modify the variable, and EXIT(FALSE) the OnModify form trigger

    Form - OnAfterGetRecord()
    OldRec.GET("No.");

    Form - OnModifyRecord() : Boolean
    IF OldRec.MyField <> MyField THEN BEGIN
    OldRec.MyField := MyField; // Update only the one field
    OldRec.MODIFY;
    END;

    Rec := Oldrec;

    EXIT(FALSE); // This is all you need not to commit the changes
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: [email protected]
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • ntnt Member Posts: 160
    ok thanks for all.
Sign In or Register to comment.