Skip to main content
Question

API_DOQUERY Javascript is not working

  • September 12, 2016
  • 0 replies
  • 78 views

Hi,

I'm testing the API_DoQuery with the following code and I'm not getting any result. Could you help me?

var promise = $.get(dbidcalendar, {

act: "API_DoQuery",

          query: "{3.EX.178}",

          clist: "3"

});

$.when(promise).then(function(xml){

var recordid = $("rid", xml).text();

});


I use something similar for API_AddRecord and API_EditRecord and it works very well. The APP does not have APPTOKEN

This topic has been closed for replies.

  • Registered
  • December 1, 2016
Hi,
https://target_domain/db/target_dbid?a=API_DoQuery&includeRids=1 &ticket=auth_ticket&apptoken=app_token&udata=mydata &query={'5'.CT.'Ragnar Lodbrok'}AND{'5'.CT.'Acquisitions'}&clist=5.6.7.22.3 &slist=3&options=num-4.nosort.skp-10.onlynew&fmt=structured
Try to understand above URL alternative method.

  • Registered
  • December 1, 2016
I use API_DoQuery as below : 

var jRecordId = "";
$.ajaxSetup({async: false});
url2 = "https://target_domain/db/target_dbid?a=API_Doquery&clist=3...;
console.log(url);
$.get(url2,function(xml){
$("record",xml).each(function(){
jRecordId = $(this).find("record_id_").text() + "\n";
});
});

  • Registered
  • December 1, 2016
Try this and note the areas where I highlighted the code:

var promise = $.get(dbidcalendar, {
  act: "API_DoQuery",
  query: "{3.EX.178}",
  clist: "3"
});

$.when(promise).then(function(xml){
  console.dirxml(xml);
  var recordid = $("record_id_", xml).text();
  console.log(recordid);
});

or chained version:

$.get(dbidcalendar, {
  act: "API_DoQuery",
  query: "{3.EX.178}",
  clist: "3"
}).then(function(xml){
  console.dirxml(xml);
  var recordid = $("record_id_", xml).text();
  console.log(recordid);
});

  • Registered
  • December 1, 2016
This will make all requests synchronous including those QuickBase makes through their own use of jQuery:

$.ajaxSetup({async: false});

Everything on the internet is asynchronous so you should learn to use asynchronous methods.

  • Registered
  • December 1, 2016
Ok Then should I use chained version? Is that asynchronous method?

  • Registered
  • December 1, 2016
Both of my versions are asynchronous. I have not written a synchronous script is a decade!

  • Registered
  • December 1, 2016
Thanks for your suggestion.

  • Registered
  • December 1, 2016
If I just remove $.ajaxSetup({async: false}); from my script then will my code become asynchronous?

  • Registered
  • December 1, 2016
Yes

Hi,
I'd really appreciate some help.. Trying to implement Dan's solution but the value I'm getting from the Do_Query is always 0..
fid_109 is called f_montominimo, and it should be a numeric value. I?m trying to get it into a variable and display on an alert (to verify it) and I use it later on in the code for other calculations.
var promise1 = $.get(gReqDBID, {
  act: "API_DoQuery",
  query: "{3.EX.QBU_key}",
  clist: "3.109"
});
$.when(promise1).then(function(xml){
  console.dirxml(xml);
  var montominimo = $("f_montominimo", xml).text();
montomin = Number(montominimo);
  console.log(montominimo);
});

I'm trying to get the rid of another table to populate into a field. I tried this with DoQueryCount to get numMatches and as it should returns "1" and puts it in fid 74. But, when i try the DoQuery below I get nothing. 
What am I missing?




var dbid="myDBID";
var apptoken = "oooolooktokens";
var pro = kRid;$.ajaxSetup({async: false}); 
var ntit = $("#_fid_9").val();
var nupc = $("#_fid_75").val();

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

var promise = $.get(dbid,{
  act: "API_DoQuery",
query: "{'35'.CT."+ntit+"}AND{'34'.CT."+nupc+"}",
  clist: "3"
});

$.when(promise).then(function(xml){
    console.dirxml(xml);
  var recordid = $("ItemID", xml).text();
 console.log(recordid);
$("#_fid_74").val(recordid);
});

  • Registered
  • May 26, 2018
More than likely this is the statement that needs to be corrected from:
var recordid = $("ItemID", xml).text();
to this:
var recordid = $("itemid", xml).text();
The XML tag is derived from the field label by lower-casing all letters and substituting an underscore for non-alphabetic characters. You should expand the xml variable in the console to see the full XML response:
console.dirxml(xml);
For what is is worth, I would make further improvements to your code such as the following:
(function() {
  var dbid = "myDBID";
  var apptoken = "oooolooktokens";
  var pro = kRid;
  var ntit = _fid_9").value;
  var nupc = _fid_75.value;
  $.ajaxSetup({data: {apptoken: apptoken}});
  var promise = $.get(dbid, {
    act: "API_DoQuery",
    query: '{35.CT.${ntit}}AND{34.CT.${nupc}}',
    clist: "3"
  }).then(function(xml) {
    console.dirxml(xml);
    var recordid = $("itemid", xml).text();
    console.log(recordid);
    _fid_74.value = recordid;
  });
})();
Also, you probably need to add decoding logic to determine what type of age you are on as I think you code is only going to work for add and edit pages.