Skip to main content
Question

JavaScript API_DoQuery failing to give the proper xml response

  • June 10, 2018
  • 0 replies
  • 90 views

function getAndSetList() {
var url = "blahblah";
getPerm();
$.get(url, {
act: "API_DoQuery",
query: "{66.IR.'last wk'}",
clist: "66"
}).then(function(xml){
console.dirxml(xml);

});
}

The above code processes the xml, but it does not find any records. FID 66 is an [End Mileage] field and I would like to see all the records with this field for the last week. I don't think there is a syntax issue with the query parameter but there is definitely something wrong with it, because I can query other fields without using IR (Is During).
This topic has been closed for replies.

  • Quickbase Alumni
  • June 10, 2018
There is a very simple explanation and fix but let me answer first by proposing a metaphor. Your situation is very similar to ordering a meal at a restaurant and immediately complaining that you didn't received anything because you didn't wait for the order to be placed, cooked and served.

We normally think of a computer as executing one instruction after another with each instruction completing before the next instruction is started. When making network requests we have to modify this step by step model because when a network request is made it takes an unpredictable amount of time before the response is actually received.

When you make a network request using jQuery's $.get(), $.post(), $.ajax(), or $.getScript() methods what is returned is not the response but an object called a promise. A promise is like a claim check at the laundry or a number ticket at the bakery in that the promise is the mechanism by which you will eventually get your result when it become available.

One way to patch up your code is to make the function getAndSetList() return a promise. Here is a version of your code that makes url a parameter to getAndSetList() and more importantly returns a promise:

function getAndSetList(url) {
  getPerm();
  return $.get(url, {
    act: "API_DoQuery",
    query: "{66.IR.'last wk'}",
    clist: "66"
  });
}

var url = "blahblah";
getAndSetList(url).then(functioin(xml) {
  console.dirxml(xml);
  //your further code here
});

Note that I have no idea what getPerm() does as it does not appear to influence the function and you did not provide any further details.

  • Author
  • Quickbase Alumni
  • June 11, 2018
Thanks for the reply as usual Dan,

One thing I'm curious about is the conceptual difference between your code and mine. My $.get() call does return a promise. Your code also returns a promise. Both code snippets, yours and mine, wait for the request to finish before proceeding. What's the subtlety here that I am missing?

Edit: Also, no need to worry about getPerm(), it doesn't influence this code, I should've just left it out.

Edit: From further analysis, it seems that your code is conceptually equivalent. I get no error from the API call, but no records are processed into the xml. I ensured the link to the table is correct. It works successfully if I query the same field but with different constraints (i.e. {'66'.EX.'0'} , also no query parameter). getPerm() returns $.ajaxSetup call. I turned async off for debugging but still, no response. I think it has to deal with QuickBase's back end implementation of the "{66.IR.'last wk'}".

Thanks

Forum|alt.badge.img
  • Quickbase Alumni
  • June 11, 2018
What type of field is  [End Mileage] ? is it a text field, or numeric, or date? If it is not a text field, then it will never return anything, since you are searching for text: 'last wk'.
If it is a text field, then maybe last week, there were no records. I would test this by putting in other text, like 'last month' or 'two weeks' or any other responses this field may have. It may be possible that it isn't returning anything due to that.