RandyGibbons
5 years agoQrew Trainee
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
------------------------------
Randy
------------------------------
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).
------------------------------
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
------------------------------