Forum Discussion

AnthonyGuillen's avatar
AnthonyGuillen
Qrew Member
28 days ago

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>

 

1 Reply

  • I do not know how to fix this but it also fails on the Code page example app and not just in your app. However I did determine that it is only failing when you have the new beta site navigation enabled. I suggest you put in a support ticket.   

    I suggest you label your support ticket as side navigation bug so it gets to the side navigation dev team.  

    If you want a poor man's, low code workaround for now, you can make a button which puts up a particular form that only has one field on it, that being the field do you want to populate. Then when you save that record it would re-display your record in the normal form. So that would be the exact same workflow.

    1 Click a button

    2. Fill in a box on a page with only one box with any prompts (Rich Text on the form)  you want, and then we display the record. All negative. No code page.  Feel free to post back if you need any help with the low tech solution.