@Brittany Scheid I had a sneaking feeling you might bring that up...
I really recommend
The Button Masterclass so that these elements can be better understood.
Several additional changes will need to be made.
1. Change your field from a URL Formula to a Rich Text Formula.
2. Change the formula to something like this:
var text RID = If(IsNull([Record ID#]),"%%rid%%",ToText([Record ID#]));
var text urlToExecute = URLRoot() & "db/" & Dbid() & "?a=er&dfid=12&rid=";
var text URL = URLRoot() & "db/" & AppID() & "?a=dbpage&pageid=6" // Open code page 6
& "&url=" & URLEncode($urlToExecute) & $RID ; // Pass in the URL to execute
var text LABEL = "Custom Save & Keep Working";
"<a class='Vibrant Success SaveBeforeNavigating' data-replaceRid=true href='" & $URL & "'>" & $LABEL & "</a>"
3. Update the code page's errRdr function
function errRdr(){
let urlParams = new URLSearchParams(window.location.search);
let url = urlParams.get('url');
// Redirects to the previous page, if this page was the previous page as well, then redirect to the app home page
if(document.referrer && document.referrer !== window.location.href) {
window.location.href = url;
}else{
window.location.href = window.location.origin + window.location.pathname;
}
}
CAUTION the use of the %%rid%% record id replacer will only work if an actual change is made to the new record before the button is pressed. (ie starting a new record and then immediately clicking the button will not force the record to save because there is nothing to save).
-Sharon
------------------------------
Quick Base Junkie
Quick Base Junkie
https://quickbasejunkie.com------------------------------
Original Message:
Sent: 05-19-2022 15:04
From: Brittany Scheid
Subject: Formula URL button - save and redirect
So that got me to the right form, but because the starting page is adding a new record, it pulled up the correct form, but for adding a new record. Is there any way to get it to save that new record, go to the pause code page, then redirect to form ID 12 for that record that was just ssaved?
------------------------------
Brittany Scheid
Special Projects Manager
SimiTree
Original Message:
Sent: 05-19-2022 15:01
From: Quick Base Junkie
Subject: Formula URL button - save and redirect
@Brittany Scheid Ahhhh, I missed that in my last reply.
On the code page, update this line of text:
window.location.href = document.referrer;
to
window.location.href = document.referrer + '&dfid=12';
assuming your form id is 12
Please note, this will render the code page less versatile for multiple uses since it will be hard coded to return to this specific form. But this is the simplest way to achive your goal.
-Sharon
------------------------------
Quick Base Junkie
Quick Base Junkie
https://quickbasejunkie.com
Original Message:
Sent: 05-19-2022 14:35
From: Brittany Scheid
Subject: Formula URL button - save and redirect
Thank Sharon. I tried this, but it's still just sending me back to the same page after it goes to the code page. I tried sending it to the form that I want and also just to the app home page and neither worked. Both times it just went back to the same edit form screen. Any thoughts? Below is the code from the formula-URL field. I used the code directly from the code page Body on this page without any changes.
var text rid = If([Record ID#]>0, ToText([Record ID#]), // Record ID already exists "%%rid%%" // New record, no Record ID exists yet );// API URL to Add/Edit/etc.var text urlToExecute = URLRoot() & "db/" & Dbid() & "?a=er&dfid=12&rid=" & $rid;//& Dbid() & "?a=er&dfid=12&rid=" & $rid;URLRoot() & "db/" & AppID() & "?a=dbpage&pageid=4" // Open code page 4& "&url=" & urlencode($urlToExecute) // Pass in the URL to execute
------------------------------
Brittany Scheid
Special Projects Manager
SimiTree
Original Message:
Sent: 05-19-2022 13:25
From: Quick Base Junkie
Subject: Formula URL button - save and redirect
@Brittany Scheid, you should be able to use the Run, Pause, & Redirect.
Only in place of an API call for the 'run', navigate to say the home page (anything away from the page you're on).
So taking the formula from the app you mentioned...
/ Creating a toggle for the Checkbox
var text toggle = If([Checkbox 2], "false", "true");
// API URL to Add/Edit/etc.
var text urlToExecute = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord&apptoken=" & [App Token]
& "&rid=" & [Record ID#] & "&_fid_20=" & $toggle;
URLRoot() & "db/" & AppID() & "?a=dbpage&pageid=6" // Open code page 6
& "&url=" & URLEncode($urlToExecute) // Pass in the URL to execute
Change the urlToExecute variable to URLRoot() & "db/" & AppID()
-Sharon
------------------------------
Quick Base Junkie
Quick Base Junkie
https://quickbasejunkie.com
Original Message:
Sent: 05-18-2022 21:06
From: Brittany Scheid
Subject: Formula URL button - save and redirect
That is helpful, thanks! Is there a way to have the action pause in between when the record saves and the next page displays? I have a pipeline that runs when the record is saved, and I want that to be finished before displaying the next page. I tried looking at the examples on Code Pages App, but the examples are either Prompt & Redirect, or Run, Pause & Refresh. I would need something like Save, Pause & Redirect. I don't know javascript really at all to be able to figure out what needs to be changed.
------------------------------
Brittany Scheid
Special Projects Manager
SimiTree
Original Message:
Sent: 05-18-2022 18:58
From: Quick Base Junkie
Subject: Formula URL button - save and redirect
@Brittany Scheid I'm glad you found a solution.
I also have a video that covers the "SaveBeforeNavigating" class (about halfway through the video below) that might be helpful to you or others. AND if you want to learn even more about building buttons in Quickbase I'd recommend The Button Masterclass.
------------------------------
Quick Base Junkie
Quick Base Junkie
https://quickbasejunkie.com
Original Message:
Sent: 05-18-2022 17:45
From: Brittany Scheid
Subject: Formula URL button - save and redirect
Never mind! I found another post that explained how to create a formula-rich text field that acts as the "Save & Keep Working". I just updated the URL to include the form ID to get what I needed. Here's the post for anyone else who's interested.
https://community.quickbase.com/communities/community-home/digestviewer/viewthread?MessageKey=d959cde4-8af7-4499-b793-c3f8807c57cd&CommunityKey=d860b0f8-6a48-487b-b346-44c47a19a804&tab=digestviewer
------------------------------
Brittany Scheid
Special Projects Manager
SimiTree
Original Message:
Sent: 11-09-2018 23:22
From: Quick Base Junkie
Subject: Formula URL button - save and redirect
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