Forum Discussion

WilliamHunter's avatar
WilliamHunter
Qrew Trainee
11 months ago

Passing data in a code page

Okay so I am a little rusty with HTML, but how do I pass information in this HTML code page? 

Code Page:

<!DOCTYPE HTML>
<html>
<body>
  <script>
    const dbid = 'btadwgxn9';   <!-- NEED TO UPDATE THIS WITH YOUR TABLE DBID -->
    const apptoken = 'c2x3rt7dkx56hnh9ckac49b2tz';  <!-- NEED TO UPDATE THIS WITH YOUR APP TOKEN -->
 
    const xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            const response = this.responseXML;
            const redirectUrl = "https://" + window.location.hostname + "/db/" + dbid + "?a=er&rid=" + response.getElementsByTagName("rid")[0].textContent+"&rl=bbv";
 
            location.href = redirectUrl;
        }
    };
 
    xhttp.open("GET", "https://" + window.location.hostname + "/db/" + dbid + "?a=API_AddRecord&apptoken=" + apptoken, true);
    xhttp.send();
  </script>
</body>
</html>

<!-- THIS CODE NEED YOUR APPLICATIONS APP TOKEN AND TABLE DBID.  UPDATE LINES 5 AND 6 ABOVE. -->

Prior to this code page I was just passing the information with a URL API call as such:

API Call

var text urlone=
URLRoot() & "db/" & [_DBID_TIME_ENTRIES] & "?a=API_AddRecord&apptoken=c2x3rt7dkx56hnh9ckac49b2tz&_fid_13=" & URLEncode ([Record ID#]) & "&_fid_18="
& URLEncode ([User's Name]) & "&_fid_25=Work" & "&_fid_104=" & URLEncode ([Supervisor])& "&_fid_105=" & URLEncode ([Foreman]) & "&_fid_106=" & URLEncode ([Job Start Time])

//& URLEncode ([Current Users Record - Maximum Record ID# User]) This line of code was dropped from the other code. It passed an alternative field.  

& "&_fid_16=In" & "&_fid_7=" & Now() & "&rdr=" & URLEncode("https://lmisystemsinc-6511.quickbase.com/db/btadwesdf/849d5088-6a1f-4ef9-a535-28c2f94bcd0b?a=showpage&pageIdV2=32602166-99b0-4ce6-9f36-5de9252afe1c");

However, long story short, this is a method I need to use in certain situations. None the less I do not know how to pass that information with an HTML code page as I was in the prior method if someone could please help. 



------------------------------
William Hunter
------------------------------

4 Replies

  • Okay, so I started to get this figured out I managed to pass a few values with the url portion. However, I dont know how to obtain the data from the current page and pass it along to the other page such as the [Record ID #] and other fields I need to obtain. 

    Code Page:

    <!DOCTYPE HTML>
    <html>
    <body>
      <script>
    const dbid = 'btadwgxn9';   // REPLACE 'btadwgxn9' with your table DBID
    const apptoken = 'c2x3rt7dkx56hnh9ckac49b2tz';  // REPLACE 'c2x3rt7dkx56hnh9ckac49b2tz' with your app token
    const fieldValue = 'Work';  // REPLACE 'Work' with the desired value for fid 25

    const xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            const response = this.responseXML;
            const redirectUrl = "https://" + window.location.hostname + "/db/" + dbid + "?a=er&rid=" + response.getElementsByTagName("rid")[0].textContent + "&rl=bbv";

            location.href = redirectUrl;
        }
    };

    const url = "https://" + window.location.hostname + "/db/" + dbid + "?a=API_AddRecord&apptoken=" + apptoken + "&_fid_25=Work" + "&_fid_16=In" ;
    xhttp.open("POST", url, true);
    xhttp.send();

      </script>
    </body>
    </html>

    <!-- THIS CODE NEED YOUR APPLICATIONS APP TOKEN AND TABLE DBID.  UPDATE LINES 5 AND 6 ABOVE. -->



    ------------------------------
    William Hunter
    ------------------------------
  • TimD's avatar
    TimD
    Qrew Trainee

    this might get you started:
    Code Pages - CopyText.html (quickbase.com)

    you put the value to be copied on the formula URL, in this case, it is the [text] field

    and then on the code page, you have this code to take that value from url

    let urlParams = new URLSearchParams(window.location.search);
    let copyText = urlParams.get('copyText');



    ------------------------------
    Tim D
    ------------------------------

    • WilliamHunter's avatar
      WilliamHunter
      Qrew Trainee

      Perfect. I will take a look here. Thank you. 



      ------------------------------
      William Hunter
      ------------------------------
      • WilliamHunter's avatar
        WilliamHunter
        Qrew Trainee

        Okay excellent got it thank you! I forgot one line of code. 



        ------------------------------
        William Hunter
        ------------------------------