Skip to main content
Solved

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

  • June 10, 2020
  • 0 replies
  • 115 views

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
------------------------------

Best answer by SamJones1

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
------------------------------
This topic has been closed for replies.

  • Quickbase Alumni
  • Answer
  • June 10, 2020
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
------------------------------

  • Quickbase Alumni
  • June 11, 2020
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
------------------------------

Forum|alt.badge.img+11
  • Quickbase Staff
  • June 11, 2020
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
------------------------------