onRecordExit script trigger

Idea created by realgrouchy on Jul 28, 2017
    Active
    Score6
    • user19752
    • realgrouchy
    • oceanwest
    • Andy Hibbs
    • jdevans
    • SteveNoble

    There have been a few threads in the Discussions section about this, but so far no Product Ideas. The gist is this:

    - There are matching OnLayoutEnter/OnLayoutExit and OnModeEnter/OnModeExit script triggers, but no OnRecordExit trigger to match the existing OnRecordEnter trigger

    - OnRecordCommit can be used as a workaround in some cases, but commits can be called in many different circumstances and there's no easy way to distinguish between them.

    - There's no way to intercept a user who is switching to another record.

     

    To avoid duplication, I'd suggest that onRecordExit would only trigger when:

    - Going to another record in the same mode/view/layout; or

    - Omitting the current record; or

    - Deleting the current record

    leaving a record (including deleting it) without changing the mode/view/layout. As for whether it would trigger when changing focus outside the window, I could go either way.

     

    Summary of related discussion threads:

    Script Trigger on Record Exit? (by MarkBanin Jan 2017, lively discussion with clunky workarounds suggested including this one by philmodjunk)

    save changes on record exit  (by AndrewJudd Apr 2016, where planteg and gabo57 suggest alternative they use but don't like, and DavidJondreau says he hasn't seen a workaround for this use case given lack of OnRecordExit script trigger)

    Lack of OnRecordExit layout trigger  (by CICT Oct 2014, lively discussion with lots of patronizing "this isn't necessary" replies)

    script trigger on record exit  (by john9210 Aug 2014, 2 posts)

     

    I consider this idea different from ( onRecordCreate, onRecordDelete and onRecordModify script triggers ) because I can imagine ways around them (maybe not onRecordDelete) and because onRecordExit would be a complement to an existing script trigger matching other complementary pairs.

     

    My use case:

    I have a "draft" field and a "saved" field for a user-entered message that gets massaged by a calculation field into an output. The user sees only the "Draft" field and I have various triggers to display previews of the draft or the saved version. However, I only ever want the "draft" field to differ from the "saved" field on the record being browsed by a user. This includes allowing the user to commit the "draft" field in order to preview the output.

     

    Therefore, when the user exits the record, they are prompted to either save or discard the draft (or cancel and return to the record). This is very easy to accomplish with script triggers for onLayoutExit and onModeExit, but without an onRecordExit script trigger, I can't stop a user from going to another record with unsaved changes (unless I want to prompt them to save their changes every.single.time they commit the record).

     

    Workaround 1: Use onRecordCommit trigger.

    - Since I need the user to be able to commit the record so that the Preview displays the output calculated from the Draft field, this won't work.

    - It is possible to exit the record without triggering onRecordCommit. In my use case, the user has created a draft and committed the record. If there were a "Save?" dialog at this point, they would opt not to because they want to view the preview. If after viewing the preview, they decide to exit the record, onRecordCommit would not trigger because no data has changed in the record, however the "draft" field is different from the "saved" field.

     

    Workaround 2: Disable the next/previous record buttons and use my own that include this trigger.

    - Since there are so many ways to change records (including keyboard shortcuts), and this database is a relatively simple one slapped together in a couple of days, I don't want to risk missing a way for the user to leave the record without being prompted (and potentially losing their changes)

     

    Workaround 3: Disable the "save record changes automatically" option for this layout and don't use a separate 'draft' field.

    - This won't work for my use case because I want the "draft" field to save automatically in order to display the preview calculated from it. I also want the other fields to still save automatically.

     

    Workaround 4: Use related table instance and global fields as described here by Phil.

    - Technically that might work, but it's too complicated and too much commitment to fill such a small gap of what I'm trying to accomplish. It has too many disparate parts that I could lose track of how they work or how to maintain them. I already have a script that works for onModeExit and onLayoutExit; it is inelegant to have to use a completely different script and a custom table and custom global field as a substitute for onRecordExit.

     

    Even if it's possible to accomplish what I'm trying with alternate means, I still can't do it easily, and an onRecordExit script trigger would fill the gap to be able to ensure that my users don't leave the record without either saving or discarding their changes.

     

    And that is just for my use case; there are probably others.

     

    Respectfully submitted,

     

    - RG>