Forum Discussion

ElishaTenenbaum's avatar
ElishaTenenbaum
Qrew Cadet
7 years ago

Formula URL button - save and redirect

Hi there

I?ve created a form accessible to ?everyone on the internet? for our clients to submit service requests. I added ?&ifv=20? to the url to hide the qb branding. However, doing this causes the save button to become hidden. I created a formula url button that will save it  using this javascript I found on the forum:

var text URL = "javascript:void(DoSaveAdd())";var Text Image = "<a id='saveButton' class='Vibrant Success' onclick='DoSaveAdd()' href='#'>Submit</a>";"<b href =" & $URL &">" & $Image & "</b>"

My problem now is how do I get the page to redirect after the form is saved. Here?s a link to the form, you can try it and see what happens.

https://sparkav.quickbase.com/db/bnzwm7ykp?a=nwr&ifv=20

I'd like it to redirect to an external webpage. If that is not natively possible than I'd like it to redirect to a rich text page I've created in quickbase.

Any help with this would be greatly appreciated!

Thanks,
Elisha
  • Submit the form with script using FormData:

    var editform = document.getElementsByName("editform")[0];
    var formData = new FormData(editform);
    formData.set("subact", "save");

    window.onbeforeunload = null;

    fetch("bnzwm7ykp?a=FinishEditRecord", {
      body: formData,
      method: "POST",
      credentials: "include"
    }).then(function(response) {
      document.location.href = "https://ibm.com";
    });

    This script (1) creates a FormData object equivalent to the QuickBase form, (2) sets the subact hidden field to "save" and (3) submits the from via fetch which returns a promise. When the promise resolves, the page redirects to ibm.com.

    Speaking of promises, I got to get me a one of those big async yard signs:



  • You can add a redirect in your formula by replacing $URL with

    $URL & "&rdr=" & $URLTWO

    You'll then need to add another variable for URLTWO (var text URLTWO = )

    You are correct that you cannot redirect outside of QuickBase, so URL TWO would be something like this (where the pageID=3 is replaced with your pageID).

    URLRoot() & "db/" & Dbid() & "?a=dbpage&pageID=3"; 

    -Sharon

    • BrianCafferelli's avatar
      BrianCafferelli
      Quickbase Staff
      You can actually do this without using JavaScript as well.

      You'll need to use the table setting called "Save parent record automatically when a child record is created." When this box is checked for your table, any time has the form open for adding / editing a record, and they click a link, they won't get the pop-up window asking if they want to save the record first. Instead, the user will see the "Saving" message briefly, then they will be redirected based on whatever link they clicked.

      You can use standard a Formula - URL here, which essentially becomes your own custom save button. Without needing to call DoSaveAdd.

    • QuickBaseJunkie's avatar
      QuickBaseJunkie
      Qrew Captain
      I was recently asked about the code I provided here and I have a better alternative using the onclick method below.

      var text SAVE = "onclick=\"$('#saveButton').click()";
      var text REDIRECT = URLRoot() & "db/" & Dbid() & "?a=dbpage&pageID=2"; 

      "<a class='Vibrant Success' & " & $SAVE & "; window.location.href=' "& $REDIRECT &" '\">SAVE & Go to Page</a>"
    • QuickBaseJunkie's avatar
      QuickBaseJunkie
      Qrew Captain
      Thanks Brian!

      I was actually working with someone who had a Save & Redirect formula that was working that did not explicitly have Save included... I was baffled for a bit then realized they had this setting you mentioned engaged. 

      Great call out!
  • Thanks Dan!

    I'm getting a syntax error on the period in the first line of the script.
    Is there a change that needs to be made to the code?
  • Elisha, there is possibly an easier solution.

    Your "add record" can specify where to go to upon Save.  ie the NextURL.

    var text ADD = URLRoot() & "db/" & [_DBIDxxxx] & "?API_GenAddRecordForm&ifv=1":

    var text RedirectTo = the url to redirect to;

    $ADD
    & "&NextURL=" & URELEncode($RedirectTo )

    • TateForgey's avatar
      TateForgey
      Qrew Assistant Captain
      I've never quite understood how redirects work and I could not get any of these solutions to work for me.  I created a URL button intended to be used in the edit view of a form that has "ifv=0" added.  No matter what I try to put in the "&NextURL" portion of this I am always just redirected to the dashboard of the app.  I don't know why.  Why?!?!

      HOWEVER, if I make sure that the "Save parent record automatically" is checked in the table's advanced settings I simply put the URL I want to redirect to in the button.  The record saves on it's own because that setting is engaged and I end up at the redirect page.  Great!  BUT.....

      These buttons do not work on mobile.  The last button I describe with the URL I want end up shows in the edit view in mobile (I haven't seen any buttons that shows up in a report) and successfully redirects to the URL. but for reasons I don't understand the record does not save.  Why?!?!

      Any ideas about how I can get a save and redirect to work in mobile?
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      I can't help you for the mobile question but if you have a question about Desktop mode i can try to help.  I'm not sure from your post above what specific question you have what your current non working code is.
    • TateForgey's avatar
      TateForgey
      Qrew Assistant Captain
      Thanks, Coach.  Let's start with the code that is your response here.  Is this a button you would put on a dashboard?  That API is going to generate the form to add a record, right?  So, it seems like it doesn't make sense to put it on a record, but maybe I'm wrong about that.

      I'm looking for a situation where I open the edit view of a record, then someone edits the record and I replace the save button with a button that saves and redirects to a rich text page I have created.  Is this type of code the way I would do that?

  • Hi there

    My apologies for the delayed response. I'm new to javascript & quickbase and at the time of my initial posting these responses were beyond my skill level. 

    I've advanced a little and decided to give these solutions another go. I�m not sure how & where to plug in these different lines of code. 

    I tried putting Dan�s code 
    1) directly into a formula-url field and I get a syntax error. 
    2) directly into a formula-rich text I�d be redirected to ibm.com whenever I viewed a record
    3) into a javascript page and loading it via iol and it would save the record but the redirect wouldn�t work

    Similar challenges with Sharons & QBChampions solutions. I'm no sure how/where to put together and plug in the code.

    I've had a bunch of success using some IOL scripts for other issues.

    Any guidance on how to plug in your answers?

    Thanks!
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      @Elisha
      My suggestion was this

      Do not make a custom save button, but rather have the user launch the Add Record off this formula URL button



      var text ADD = URLRoot() & "db/" & [_DBIDxxxx] & "?API_GenAddRecordForm":

      var text RedirectTo = the url to redirect to;

      $ADD
      & "&NextURL=" & URELEncode($RedirectTo )


      You can build that button on a any record and copy the generated code and paste it into a dashboard button.  The formula with them calculate the URLEncoding.


    • QuickBaseJunkie's avatar
      QuickBaseJunkie
      Qrew Captain
      Both my and Mark's (QB Coach) suggestions work in the Formula URL field.

      Here is the formula I suggested more explicitly written out using your inital formula as a base:

      var text URL = "javascript:void(DoSaveAdd())";
      var text URLTWO = URLRoot() & "db/" & Dbid() & "?a=dbpage&pageID=3"; 
      var Text Image = "<a id='saveButton' class='Vibrant Success' onclick='DoSaveAdd()' href='#'>Submit</a>";
      "<b href =" & $URL & "&rdr=" & $URLTWO &">" & $Image & "</b>"

      (where the pageID=3 is replaced with your pageID).

      -Sharon
    • Rohit's avatar
      Rohit
      Qrew Trainee
      Hi,
      None of these suggestions works in my case. Any help is greatly appreciated!

      I'm in the edit mode for a record that already exists. I need to save the current record which triggers certain form rules and automations and then I want to redirect back to the parent record on a specific form. Is this possible?

      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend
        I think this is an easy one

        Go to the child table and Advanced Properties and check the box for
        Save parent record automatically when a child record is created

        Then just make a URL formula link to go to the parent record in edit mode.

        URLRoot() & "db/" & [_DBID_Parent_Table_Alias] & "?a=er&rid=" & [related parent]

        Then when you click that link to navigate away from the child which has been "dirtied" with unsaved input, Quick Base will auto save and then go to your link.




        ------------------------------
        Mark Shnier (YQC)
        Quick Base Solution Provider
        Your Quick Base Coach
        http://QuickBaseCoach.com
        mark.shnier@gmail.com
        ------------------------------