AnthonyGuillen
10 months agoQrew Member
Code Page - Refresh not working
I have a URL Formula button on a record form, whose purpose is to prompt user for text input, update a text field with that input, and change status of record to "Done".
I used the "Prompt for Input and Refresh" example in the code pages samples: https://resources.quickbase.com/db/bq8mgh24g?a=dr&rid=10414
After clicking the button, the field value updates, but the rather than display the record refreshed, I get an error: 404 Error, Page Unrecognized.
So the first part of fetch code is executing correctly, but it seems the redirect is what is failing.
Any help would be appreciated!
Here's my button code:
var text urlToExecute = URLRoot() & "db/" & Dbid() &
"?a=API_EditRecord&apptoken=MYAPPTOIKEN&rid=" & [Record ID#] & "&_fid_26=";
URLRoot() & "db/" & AppID() & "?a=dbpage&pageid=5" // Open code page 5
& "&url=" & URLEncode($urlToExecute) // Pass the URL to execute
Here's the script and form portion of my code page 5:
<script>
function run() {
$('#form').hide();
$('#status').show();
const input = document.getElementById('input').value;
let urlParams = new URLSearchParams(window.location.search);
let url = urlParams.get('url') + encodeURIComponent(input);
let redirect = urlParams.get('redirect');
let landing;
if(redirect){
landing = redirect;
}else{
landing = document.referrer;
}
fetch(url, {
method: 'post',
mode: 'no-cors',
headers: { 'Content-type': 'text/plain' }
}).then((response) => {
rdr(landing);
})
}
function rdr(landing){
// Redirects to the specified landing page, if this page is the landing page as well, then redirect to the app home page
if(landing && landing !== window.location.href) {
window.location.href = landing;
}else{
window.location.href = window.location.origin + window.location.pathname;
}
}
</script>
<div class="container" id="form">
<h2>Input Needed</h2>
<form onSubmit="run();">
<div class="form-group">
<label for="input">Please provide some input</label>
<input class="form-control" id="input" autofocus>
</div>
<a class="btn btn-primary" onclick="run()" role="button">Submit</a>
<a class="btn" onclick="window.location.href = document.referrer;" role="button">Cancel</a>
</form>
</div>
<div class="container" id="status" style="text-align:center" hidden>
<h2>Making API Calls, will redirect once complete.</h2>
<div class="loader" id="loader"></div></div>
<br>
</body>
</html>