Forum Discussion

MiguelSoto's avatar
MiguelSoto
Qrew Trainee
4 years ago

Code Page execution

I have two Code page in that pages I do some quickbase API call and I create a functions inside, the doubt is if its possible to call a function in Page1 from page2 to avoid write the same code in both pages?


Any idea?

Thanks

3 Replies

  • You can use jquery's GetScript to add the code, i.e.
    $.getScript("mydomain.quickbase.com/db/appid?a=dbpage&pagename=my_script.js", function() { alert("Tada, script is loaded"); });


    ------------------------------
    Ben Smith
    ------------------------------
  • Hey, 

    You can use JS Modules to export/import code between pages.

    JavaScript Modules (w3schools.com)

    You would have to put the URL address of your application, with the table ID and page ID appended in the import function and add type="module" to your script tags in your HTML.

    Code page (HTML):
    <script type="module" src="https://mycompany.quickbase.com/db/?a=dbpage&pageID=[PAGE_ID]"></script>

    Code Page (JS) 1 ():

    export default let myFunction = () => {
            // Some code here 
    }

    Code Page (JS) 2:
     
    import myFunction from "https://mycompany.quickbase.com/db/
    ?a=dbpage&pageID=[PAGE_ID]"
    In theory this should work, however, I haven't tried it myself.
    You could also try adding another script tag to your html pointing to the other JS file.

    ------------------------------
    Luke Stone
    ------------------------------
  • You can create a third page with only your shared functions and import it with a script tag.
    You can even host that page outside quickbase on any CDN

    ------------------------------
    Simon H
    ------------------------------