Forum Discussion
I'm familiar with the method you outline. Kirk had his URL formula call a code page, which isn't working.
I use a code page that I found on the Magic Buttons app to capture the current time.
I also found code page that I can call from a button to open a popup window and then get the current lat/long. (attached), but I don't know how to get what I need from it. It works, but not on a mobile.
------------------------------
Barry Dolan
------------------------------
At this point it would really just be trial and error with that code you linked above. That code is valid for modern browsers and should remain working on mobile, however you'll likely need to play around and attempt to tweak the response and display the full error string on screen so you can actually see what's going on.
Its possible that the configuration of the button as a pop up isn't working since its on a mobile device, or there might be something about your device settings that is blocking your device from responding to the geolocation API. Someone else on this forum might chime in later with existing code that you could copy, but best course now is just to play with that existing code and figure out what, if any errors are responding once you cross over to mobile.
------------------------------
Chayce Duncan
------------------------------
- BarryDolan2 years agoQrew Cadet
The frustrating part is, I know it works, I just don't know how to pass the results back to form.
I can run the little popup and get the lat/long, so, in theory, I should be able to run some of that code to get the lat/long and pass it back to my fields.
Attached is the code that captures the coordinates to display on the popup.But then what???
------------------------------
Barry Dolan
------------------------------- ChayceDuncan2 years agoQrew Captain
Ah, well that is the easy part then. Once you have the results logged you would use the QB API to log it back to your record. Since your example says they're clocking in, then you'd be adding a record so you don't need anything like a Record ID parameter or anything. You can use either the HTTP API or the REST API, I've given an example of using the REST API below.
Using the REST api you need to get a temp token for the user logged in using a function like:
const tempToken = (dbid) => {return new Promise((resolve,reject) => {var headers = {'QB-Realm-Hostname': 'your realm','QB-App-Token': 'your app token','Content-Type': 'application/json'}fetch(`https://api.quickbase.com/v1/auth/temporary/${dbid}`,{method: 'GET',headers: headers,credentials: 'include'}).then(res => {if (res.ok) {return res.json().then(res => resolve(res.temporaryAuthorization));}return res.json().then(resBody => reject({status: res.status, ...resBody}));}).catch(err => reject(err))})}You also need an upsert function to load it to QB - something like:const upsert = (commit,token) => {return new Promise((resolve,reject) => {var headers = {'QB-Realm-Hostname': 'your realm','Authorization': `QB-TEMP-TOKEN ${token}`,'Content-Type': 'application/json'}var body = {to: dbid to load to,data: commit,}fetch('https://api.quickbase.com/v1/records',{method: 'POST',headers: headers,body: JSON.stringify(body)}).then(res => {if (res.ok) {return res.json().then(res => resolve(res));}return res.json().then(resBody => reject({status: res.status, ...resBody}));}).catch(err => reject(err))})}Put it all together in your code like:
function showPosition(position) {
tempToken(your dbid).then((token) => {
var commit = [
{
"fid of your latitude field": { value: position.coords.latitude },
"fid of your longitude field": { value: position.coords.longitude },
"fid of your date/time field": { value: code to get the date/time you want}
}
]
upsert(commit, token).then((res) => {
//handle the qb response here and redirect if successful
}).catch((err) => { // handle errors here })
})
}
Disclaimer is that you'll need to modify this code to fit your actual need and inject your own code to handle errors or any issues with syntax or formatting. It's hard to code directly into this interface so there might be syntax errors that would be easier to spot in a text editor.
------------------------------
Chayce Duncan
------------------------------- BarryDolan2 years agoQrew Cadet
I am definitely going to keep the snipet. Thank you. But I lost you right after you said "easy part", lol!
For our purposes the user does not create a new record each time they clock in/out. This function updates an existing record, like a time card.
var text urlToExecute = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord&apptoken=ca5f4i4b5f6y8vy7zfzcfvximk"
& "&rid=" & [Record ID#] & "&_fid_64="&ToTimeOfDay(Now());I wrote a scheduled pipeline that creates a set of records each day. The user then has a new record to use as their time card for each workday.
I am going to place 2 new fields beside the clock in field to record the lat/long when the button is tapped. And follow the same with the clock out button tap.
------------------------------
Barry Dolan
------------------------------
Related Content
- 24 days ago
- 7 months ago
- 11 months ago