Forum Discussion

RandyGibbons's avatar
RandyGibbons
Qrew Trainee
4 years ago
Solved

IOL working (JSON) would like to save to field in form

I was able to use IOL and read in the data from the JSON API using the model.js (below), pass a variable (satellite) and see the data in the console after pressing the button (props to Diebolt! and his pasties).  This is using just a basic ISS satellite tracking API.  The Key field for the form is the satillite number [satillite], which in this case is the ISS, which is the variable I'm passing.

Page: module.js
(function(){
  var dbid = "application dbid";
  var dbidTable = "table dbid";
  var apptoken = "app token";
  $.ajaxSetup({data: {apptoken: apptoken}});
  $("a.QBU_Button").on("click", function(event) {
    console.log("onclick in module.js");

    var satellite = this.dataset.satellite;
    console.log("Satellite#:", satellite);

    var url = "https://api.wheretheiss.at/v1/satellites/";
    var options = {
      id: satellite,
      format: "JSON"
    }
    
    $.get(url, options).then(function(resp) {
      console.log("Latitude:", resp.latitude);
      console.log("Longitude:", resp.longitude);
      console.log(JSON.stringify(resp, null, "  "));
    	
    });
  });
})();


Button: (rich text formula)

[iol] & "module.js" & [/iol]
&
"<a class='QBU_Button Vibrant Success' " &
"  data-satellite='" & [satellite] & "'" &
">Button</a>"


What I can't figure out is how to take the resp.latitude value and use the API_EditRecord to insert the latitude value into the current record into Field 7 Latitude (text field).

Any thoughts on this?  Thanks!

------------------------------
Randy
------------------------------
  • Hey Randy,
    First off, I'd avoid Image on Load. It'll break at some point in the future.

    That said, if it's writing to the console successfully, you should be able to add this:

    $("#_fid_7").val(resp.latitude)​

    And that should add it to the record that's on the screen.


    ------------------------------
    - Sam

    ______________________________________________
    Sam Jones
    Vice President, Product and Technology
    he/him

    The Data Collaborative, Inc.
    sjones@datacollaborative.com
    366 Massachusetts Ave, Suite 203 | Arlington, MA 02474
    ------------------------------

6 Replies

  • Hey Randy,
    First off, I'd avoid Image on Load. It'll break at some point in the future.

    That said, if it's writing to the console successfully, you should be able to add this:

    $("#_fid_7").val(resp.latitude)​

    And that should add it to the record that's on the screen.


    ------------------------------
    - Sam

    ______________________________________________
    Sam Jones
    Vice President, Product and Technology
    he/him

    The Data Collaborative, Inc.
    sjones@datacollaborative.com
    366 Massachusetts Ave, Suite 203 | Arlington, MA 02474
    ------------------------------
    • RandyGibbons's avatar
      RandyGibbons
      Qrew Trainee
      Thanks Sam, worked like a champ!  Just need to be in Edit mode for it to populate, but no issues.  Added it after the bottom console.log lines.

      What other solution would you suggest based on this?  I know there are pipelines, but our org has them disabled at the realm level.

      Randy

      ------------------------------
      Randy Randy
      ------------------------------
      • SamJones1's avatar
        SamJones1
        Qrew Cadet

        Randy,
        I'd lean toward having a url formula like this:

        urlroot() & "db/" & appid() & "?a=dbpage&pageid=5&satellite=" & [satellite]

        Pass that off to a code page (in this case page 5), have the code page make the API call, then call the following:

        var targetTable = "dbid of the table you want to create a record on"

        window.location.href= 'https://quickbase.com/db/' + targetTable + '?a=api_genaddrecordform&_fid_7=' + resp.latitude;


        That'll open a new record form with the value pre-populated. If you want to do that with an existing record, set up a call with me and we can talk through it.

        https://calendly.com/samrjones



        ------------------------------
        - Sam

        ______________________________________________
        Sam Jones
        Vice President, Product and Technology
        he/him

        The Data Collaborative, Inc.
        sjones@datacollaborative.com
        366 Massachusetts Ave, Suite 203 | Arlington, MA 02474
        ------------------------------
  • To accomplish this in JavaScript, you would need to do another call through the API to edit the record, you wouldn't have to be on the edit form.

    This is assuming IOL, I've been using it for two years on the platform, and personally, I foresee QB will have a lot of issues if they do get rid of it, without some form of in depth custom options for us clients on their pages...

    On top of what Sam has mentioned, if you wanted to edit the record directly, you can also do a call such as (JQuery since QB has it natively):

    var domain = window.location.hostname;
    var dbid = (hard code or softcode);
    var rid = kRid; //This is a global variable of Record ID of the page (desktop only, not mobile)
    var longFid = (field ID of longitude field);
    var latFid = (field ID of latitude field);
    var apptoken = (if needed per your applications settings);

    $.post(
    `https://${domain}/db/{dbid}?a=API_EditRecord&rid=${rid}&_fid_${latFid}=${resp.latitude}&_fid_${longFid}=${resp.longitude}`); //add &apptoken=${apptoken} if needed.

    With this being done in the browser, usertoken isn't necessary as this will work with the current session's credentials.



    ------------------------------
    Ryan Stanford
    ------------------------------
  • hhersch's avatar
    hhersch
    Qrew Captain
    Hi Randy. As @Sam Jones mentioned, any sort of unsupported syntax in Quick Base is not durable and likely to break in the short term. This is only more likely as we increase our efforts to modernize our UI. The supported model for something like this would either be Pipelines or having a button that launches a JavaScript code page to do your queries and then uses the API to write the data back to Quick Base. Similarly, leveraging our internal libraries might cause stability issues for you because we update them regularly. You can read more about best practices here.​

    ------------------------------
    Harrison Hersch
    ------------------------------
    • RandyGibbons's avatar
      RandyGibbons
      Qrew Trainee
      Thank you both very much.  I will work with the code to see if I can get it both ways, just in case the IOL does go away.  Can't thank you both enough!

      ------------------------------
      Randy Gibbons
      ------------------------------