Discussions

Expand all | Collapse all

Refresh Current Page After Save & Keep Working

  • 1.  Refresh Current Page After Save & Keep Working

    Posted 06-23-2021 13:52
    I have a table (Assets) with a custom key called Asset ID (default value of 1). In order to set Asset ID, I am using a calculated field (temp id) that is
    set to Record ID# + 10M (Asset ID is used by an external system and needs to be a large number). I have a pipeline that runs when a record is created in the Assets table that has an Asset ID of 1. The pipeline updates the Asset ID to the value in temp id.

    When the user enters a new Asset (completes the form and saves it), I would like the Asset ID to be displayed on the form. To complicate this a little more, I have a child table (Versions) and on the Assets form, there are tabs for both Asset and Versions (an Asset can have many versions). The Versions tab contains an embedded report of all associated Versions (blank initially) and it also includes the Asset ID. The pipeline that runs to update the Asset ID also creates a Versions child record, which contains some basic information from the parent (including Asset ID). So, the end goal is to have Asset ID visible on both the Asset and Versions tabs. Currently, when a record is saved, I have both the Record ID# and temp id in hand. However, in order for the Asset ID and Versions child record to display, I have to refresh my browser window. My goal is to get them to display without the user having to take any additional actions (aside from the initial save of the record).

    I am currently playing with a custom "save and keep working" button and am trying to add a page refresh following the save, but I can't seem to force a page refresh.  I'm a relative newbie and am trying some things I've found on Community.  (Questions - when should I use URLENCODE?  And what does rdr do (redirect?)?) 

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

    // create Edit Record URL & RefreshPage variables
    var text url = URLRoot() & "db/" & Dbid() & "?a=er&rid=" & $rid;
    var text RefreshPage = URLRoot() & "db/" & Dbid() & "?a=doredirect&z=" & $url;
    //var text RefreshPage = URLRoot() & "db/" & Dbid() & "?a=doredirect&z=" & Rurl();

    "<a class='Vibrant Primary SaveBeforeNavigating' data-replaceRid=true href='" & $url & "&rdr=" & $RefreshPage & "'>Save & Keep Working - Rich Text</a>"
    // "<a class='Vibrant Primary SaveBeforeNavigating' data-replaceRid=true href='" & $url & "&rdr=" & URLENCODE($RefreshPage) & "'>Save & Keep Working - Rich Text</a>"

    ------------------------------
    Dawn Quitschau
    ------------------------------


  • 2.  RE: Refresh Current Page After Save & Keep Working

    Posted 06-23-2021 17:04
    Edited by Sharon Faust (QuickBaseJunkie.com) 06-23-2021 18:50
    The rdr is only used when you have multiple actions happening. Here you just need to save while staying on the page. Also the %%rid%% can't be URL Encoded to function properly, but since you're not redirecting to a second function, you don't need it.

    The ?a=doredirect&z=" & Rurl() is something else entirely. It takes the user back to where they originally pressed the button (like a parent record or a report.

    Below is all you really need. Just make sure you also have the box in the table's advanced settings to "Auto save when redirected away from the page".

    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>"

    One other thing to keep in mind is that for the record to save an actual edit to a field must be present. If someone just clicks the button without editing anything it won't save.

    ------------------------------
    Sharon Faust (QuickBaseJunkie.com)
    Founder, Quick Base Junkie
    https://quickbasejunkie.com
    ------------------------------



  • 3.  RE: Refresh Current Page After Save & Keep Working

    Posted 06-24-2021 12:18
    Sharon, thanks for the quick response.  The code you provided is what I started with when I created my custom button, however, it still doesn't return the updated Asset ID.  (It appears to perform the same functionality as the native Quickbase "Save and Keep Working" button.)  I can see the record was saved and it does return the Record ID# and temp id, but the Asset ID is still set to 1.  If I click on the browser refresh button to manually refresh the browser window, the updated Asset ID appears.  So somehow, I need to mimick that functionality.  Or provide a delay between the save and re-display to allow the pipeline to run following the save.

    ------------------------------
    Dawn Quitschau
    ------------------------------



  • 4.  RE: Refresh Current Page After Save & Keep Working

    Posted 06-24-2021 14:50
    Ah, okay.

    Using a Pipeline in this scenario to update the key will be slow, so I wouldn't take that route for the first part (updating the key).

    I have 2 suggestions:
    1. Use a form rule to copy the temp id to the Asset ID on save. Below is an image of an example that I have working in an app where the "Rate ID (Rate Type)" is the key field. I like this option because you can use the native save buttons.
      Formula rule for key field
    2. Use an API action button to copy the value from the temp id to the Asset ID. This would be the approach you originally started with but with the addition of the API. It would require the user to use this button in order for the key to update. Below is the button I'd create if I were doing this myself. (Note the key field id '7' on line 5 would need to be updated with the id for the Asset ID, the [Temp ID] for your field name, as well as the apptoken on the next line).
    var text NEW =
    URLRoot() & "db/" & Dbid() &
    "?a=API_EditRecord" &
    "&rid=%%rid%%" &
    "&_fid_7=" & URLEncode([Temp ID]) &
    "&apptoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxx" & 
    "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?a=er&rid=") & "%%rid%%";
    
    var text SAVE = 
    URLRoot() & "db/" & Dbid() &
    "?a=er&rid=" & [Record ID#];
    
    var text URL = If(IsNull([Record ID#]),$NEW,$SAVE);
    
    "<a class='btn btn-md btn-success SaveBeforeNavigating' style='color:white; text-decoration:none;' data-replaceRid=true href='" & $URL & "'>Save & Keep Working</a>"​


    If you want to learn more about action buttons I have a free toolbox called the Action Button Toolbox.

    And I also have a course on API buttons specifically called the Secrets of API Buttons that goes into a ton of detail on the components used in the formula above (and a whole lot more).

    -Sharon

    ------------------------------
    Sharon Faust (QuickBaseJunkie.com)
    Founder, Quick Base Junkie
    https://quickbasejunkie.com
    ------------------------------



  • 5.  RE: Refresh Current Page After Save & Keep Working

    Posted 06-25-2021 21:47
    Sharon, I tried both of these approaches and I get the same error - when I click on "Save and Keep Working" (native QB button in the first example) I get a pop-up that says "On the tab Asset, the field Asset ID is required."  When I click OK, I'm returned to the Assets form, which is showing the Asset ID is blank and temp id is set to 3 question marks (???).  

    ------------------------------
    Dawn Quitschau
    ------------------------------



  • 6.  RE: Refresh Current Page After Save & Keep Working

    Posted 06-28-2021 13:50
    I'm not sure why you're getting that and I didn't in my tests. Here are some questions to help you troubleshoot.

    How is the formula derived? What are the inputs? Do they come from a relationship?

    Also, do you still have the default id of "1" entered in the Asset ID field?

    ------------------------------
    Sharon Faust (QuickBaseJunkie.com)
    Founder, Quick Base Junkie
    https://quickbasejunkie.com
    ------------------------------