Roll back of data when error in OnModify of record

happyjoy
happyjoy Member Posts: 10
On my vendor record I have set the NONBLANK property of the "Shipping Agent Code" to YES so it cannot be blank. A user opens the Vendor form, presses F3 for a new record. This runs the OnInsert trigger and gives a new numbered blank vendor record. The user then keys the vendor name, address, etc... and hits scroll to go to the next record, or tries to close the form.

At this point, the error occurs that says "Shipping Agent Code cannot be blank". That's great.. 8) ....except all the data they've entered disappears because the record is rolled back after the error occurs #-o .

How do I get the data they key to stay on the record after the error occurs?
"For in much wisdom is much grief, and he who increases knowledge increases sorrow." - Eccl. 1:18

Answers

  • ayhan06
    ayhan06 Member Posts: 210
    happyjoy wrote:
    On my vendor record I have set the NONBLANK property of the "Shipping Agent Code" to YES so it cannot be blank. A user opens the Vendor form, presses F3 for a new record. This runs the OnInsert trigger and gives a new numbered blank vendor record. The user then keys the vendor name, address, etc... and hits scroll to go to the next record, or tries to close the form.

    At this point, the error occurs that says "Shipping Agent Code cannot be blank". That's great.. 8) ....except all the data they've entered disappears because the record is rolled back after the error occurs #-o .

    How do I get the data they key to stay on the record after the error occurs?

    simple way to do this check is :
    1. Set InitialValue of Block field as "All"
    2. OnValidate trigger of "Block" trigger, check that shipping agent code is filled in.
    3. tell your users to unblock vendor after entering vendor informations.
    PS: crosscheck may be needed in OnValidate trigger of shipping agent code
  • happyjoy
    happyjoy Member Posts: 10
    That would work on initial record entry, but nothing prevents them from blanking it out later on when Blocked is blank. The field cannot be blank on a Vendor - ever.
    "For in much wisdom is much grief, and he who increases knowledge increases sorrow." - Eccl. 1:18
  • kine
    kine Member Posts: 12,562
    THan you can add code which will again block the record when someone clear the field... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ajhvdb
    ajhvdb Member Posts: 672
    Yes, from experience this is the only nice way to do it.
  • happyjoy
    happyjoy Member Posts: 10
    Sounds like a plan! Thanks to all! :D
    "For in much wisdom is much grief, and he who increases knowledge increases sorrow." - Eccl. 1:18
  • Savatage
    Savatage Member Posts: 7,142
    well if you set the field to NotBlank and you use the above example to block on insert & testfield - you will not be able to blank the field out - it will always need a value