My API_DoQuery not returning the date

  • 0
  • 1
  • Question
  • Updated 7 years ago
  • Answered
Here are the details

$(document).ready(function() {

url = "https://www.quickbase.com/db/boomboomact=API_DoQuery&query={'3'.EX.'recordID'}&clist=2&slist=2&appto...;
//alert(url);
$.get(url,function(xml) {

var date= $(xml).find("date_modified"); //---This line returns [object Object]
I want it to return the date when it was modified.
alert(date);
document.getElementById('getTime').value = date;
});

<body>
<input type="text" id="getTime">
<input type="button" value="Clear Forecasts" onCLick= clearMe()
<p> <b> <font color=red>This Button is to be used once a month</font> </b></p>
</body>

I know i am doing something wrong. Any Suggestions.


Photo of Azh7

Azh7

  • 30 Points

Posted 7 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
You are missing the text() method. Try one of these equivalent statements:

var date= $(xml).find("date_modified").text();
var date= $("date_modified",xml).text();

Also, I would avoid synthesizing an absolute URL. To avoid having to modify your code in the future (because of the subdomain issue in the new UX) ALWAYS user relative URLs. The base URL for all QuickBase pages is https://subdomain.quickbase.com/db/ so to generate relative URLs you only have to specify the dbid or main for the URL. Your browser will translate the relative URL into an absolute URL automatically specifying the correct subdomain. The same advice applies to writing formulas: Stop hardcoding "https://www.quickbase.com/db" or using URLRoot() in your formulas.

https://www.quickbase.com/db/6ewwzuuj?a=dr&rid=150
Photo of Azh7

Azh7

  • 30 Points
var date= $(xml).find("date_modified").text(); //this is giving a blank value
var date= $("date_modified",xml).text();   

both are returning a blank value
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
Works for me when called against Formula Function Reference table in the QuickBase Support Center application:

$.ajaxSetup({
data: {
apptoken: "bbx8vred9cvtf45f66z5czpeg79"
}
});

var promise1 = $.get("6ewwzuuj",{
act: "API_DoQuery",
query: "{'3'.EX.'37'}",
clist: "a"
});

$.when(promise1).then(function(xml1){
var ms = parseFloat($("date_modified",xml1).text()); // 1172525140165
console.log(new Date(ms).toString());
//Mon Feb 26 2007 16:25:40 GMT-0500 (Eastern Standard Time)
});

[Record ID#]=73 is this record:

https://www.quickbase.com/db/6ewwzuuj?a=dr&rid=73

Note this application was set up to not require application tokens. Although I include an application token in the default AJAX setup, QuickBase simply ignores it because it is not required. Following this code pattern will allow you to only specify the application token once.
Photo of Azh7

Azh7

  • 30 Points
$.get("blahblah?act=API_EditRecord&rid="+recordID+"&_fid_142=&_fid_143&_fid_144=&apptoken="+apptoken+"",function(xml) {

console.log(recordID+" modified");
});

I am getting this error mesg:
<qdbapi> <action>API_EditRecord</action>
<errcode>24</errcode>
<errtext>Invalid Application Token</errtext>
<errdetail>An Application Token must be supplied.</errdetail>
</qdbapi>

I am passing the application token but still it is given me an error.... This is being used inside a loop, just wanted to let you know..
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
Debug:
  1. Why are you appending what appears to be an empty string after the apptoken value ( +"" ) ?
  2. Check your apptoken again
  3. Temporarily turn off apptokens and retest
  4. prompt("url",url) and cut and paste into new browser tab. Note this will be a relative URL so pad it appropriately.
Photo of Azh7

Azh7

  • 30 Points
apptoken is not an empty string...
There just a minor error in the url that i was using(missed the "=" after 143).....
Now its working fine...Thanks
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
You should migrate to this pattern of using $ajaxSetup(), data object, and promises:

var apptoken = ...
var recordID = ...

$.ajaxSetup({
data: {
apptoken: apptoken
}
});

var promise1 = $.get("blahblah",{
act: "API_EditRecord",
rid: recordID,
_fid_142: "",
_fid_143: "",
_fid_144: ""
});

$.when(promise1).then(function(xml1){
console.log(recordID+" modified");
});

Your code will be much cleaner, shorter and easier to maintain over time. You can also hoist additional hard-coded parameters such as "blahblah" to a variable dbid defined at the top of passed as a parameter if you package your code as a function.
Photo of Azh7

Azh7

  • 30 Points
Thank You...will keep that in mind...
Photo of Azh7

Azh7

  • 30 Points
I needed your suggestion on one of my task,
I am clearing up 3 fields using a button depending on some condition... I am using API_DoQuery and and than using a loop and editing the records using API_EditRecord.. This is not efficient as i have many records..
I was thinking of using SQL for this, can you guide me how to do this, or if not , any other suggestion....
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
Use API_ImportFromCSV to change multiple records in one call versus multiple calls to API_EditRecord.

There is no SQL availble with QuickBase.

This conversation is no longer open for comments or replies.