Forum Discussion

ChristopherGre3's avatar
ChristopherGre3
Qrew Trainee
2 years ago

Save and Keep Working behavior in a Custom button

The native behavior of Save & Keep Working will save Both the edit made to embedded child records and whatever changes made in the form to the parent record. The code below Does Not do that. I found the below at: Alternatives to common JavaScript Insertion techniques

var text rid = If([Record ID#]>0, ToText([Record ID#]), "%%rid%%"); 

var text url = URLRoot() & "db/" & Dbid() & "?a=er&rid=" & $rid; 

 "<a class=\"Vibrant Primary SaveBeforeNavigating\" data-replaceRid=\"true\" href=\"" & $url & "\">Save & Keep Working - Rich Text</a>" 

My endeavor is to have a Custom Button behave the same way as the Native "Save & Keep Working" button. Save both parent and child record edits, redisplay in edit mode. Why a custom button? you may ask. Because the other options "Save & Close" and "Save & Next" I do not want to be available to the end user. Any assistance is appreciated. 
Thank you,
CGreene



------------------------------
Christopher Greene
------------------------------

8 Replies

  • MarkShnier__You's avatar
    MarkShnier__You
    Qrew #1 Challenger
    Is the problem that the button fails if the only changes to the record are in the grid edit?

    ------------------------------
    Mark Shnier (Your Quickbase Coach)
    mark.shnier@gmail.com
    ------------------------------
    • ChristopherGre3's avatar
      ChristopherGre3
      Qrew Trainee
      Not the only change, but one of the changes - either, or. If I were to make an edit to the main parent record only, then the custom button works. If I make an edit to the embedded child records, regardless of whether I make an edit to the parent, then click my custom button, QB behaves as if I'm navigating away before the save with the message, "Leave site? changes you made may not be saved".

      ------------------------------
      Christopher Greene
      ------------------------------
  • I'm not totally tracking the issue, but your button is just opening a record in edit mode vs. displaying the record (the url query string contains a=er vs. a=dr), so it seems like the record is just reloading without saving changes, right?

    Have you reviewed the Table Advanced Settings to ensure the "Auto save when redirected away from the page" box is checked?

    Also, it sounds like you are aware, but on the Form level (not Table level) we can control button visibility via the "Show Save & close and Cancel buttons at the end of this form" and "Show save & keep working choice" boxes. So an alternative solution may be to create a separate form and assign this form as the default for Users in certain Roles. You can point the Users in a given form using the dfid=[YourFormID] query string parameter and in the Form UI to use the native QB controls. I'm not sure that's a feasible option in your use case, but wanted to throw it out there!

    See attached screenshots.

    ------------------------------
    Brian
    ------------------------------
    • MarkShnier__You's avatar
      MarkShnier__You
      Qrew #1 Challenger
      @Christopher Greene

      The SaveBeforeNavigating syntax is known to fail i.e. (causing that pop up) if the only change to the record was In Grid Edit. I have found that it works reliably if the Parent record is changed. What I finally settled on which works perfectly is to make to helper fields on the form. One is called [Dirty the record] and the other one is called [Dirty the record plus 1].  The latter is a formula field obviously equal to

      [Dirty the record] +1`

      I then have a form rule set to fire all the time where if those two fields are not equal I change [Dirty the record] to be equal to the value in the field [dirty the record plus 1].  

      In your post above you are claiming that save before navigating fails even if both the parent and the child have been modified. In my experience that is not how it behaves. Try putting in that form rule and see if it solves the problem.   ​

      ------------------------------
      Mark Shnier (Your Quickbase Coach)
      mark.shnier@gmail.com
      ------------------------------
      • ChristopherGre3's avatar
        ChristopherGre3
        Qrew Trainee
        Mark,
        Your provided solution works great when only the embedded child records themselves are edited when the main parent record is not necessarily changed. 
        Thank you for the helpful tip. Much appreciated.
        CGreene

        ------------------------------
        Christopher Greene
        ------------------------------