Forum Discussion

ShaneDavis's avatar
ShaneDavis
Qrew Member
5 years ago
Solved

API_DoQueryCount with parameterized saved query (qid)

I have what I'd have expected to be a simple need: to get the # of records matching a saved query that requires one "ask the user" parameter.

It seems that API_DoQueryCount when using a saved query (qid=) doesn't work with report parameters (nv=1, v0="foo"); I get <numMatches>0</numMatches> every time, even though the API_DoQuery invocation with the same parameters returns records. If true, it's a real head-scratcher of an API limitation. The documentation is vague (doesn't even make clear that qid is a supported parameter for API_DoQueryCount, though it works for qids with no parameters required).

Is there an alternative way to do what I need to do, since it seems the intuitively obvious one isn't implemented?

------------------------------
Shane Davis
------------------------------
  • I don't think there is a way to provide query parameters when using an ID or query name.  I've always provided the query when I use the API, that has the added benefit of providing some change management since it's more difficult for other users to change my source code than a report in Quick Base.  If you're trying to use the QID because you're not sure how to construct the same query using the query syntax, you can use API_GetSchema on the table with the report and look for the qycrit element for the query with the same ID number and you can see the query syntax there.  All you have to do is replace the '_ask#_' with your parameters and you should be able to call API_DoQueryCount and get the expected results.

    ------------------------------
    Nathan Hawe
    ------------------------------
  • I don't think there is a way to provide query parameters when using an ID or query name.  I've always provided the query when I use the API, that has the added benefit of providing some change management since it's more difficult for other users to change my source code than a report in Quick Base.  If you're trying to use the QID because you're not sure how to construct the same query using the query syntax, you can use API_GetSchema on the table with the report and look for the qycrit element for the query with the same ID number and you can see the query syntax there.  All you have to do is replace the '_ask#_' with your parameters and you should be able to call API_DoQueryCount and get the expected results.

    ------------------------------
    Nathan Hawe
    ------------------------------
    • ShaneDavis's avatar
      ShaneDavis
      Qrew Member
      This works, much appreciated! Code was already calling API_GetSchema to get some other metadata, thus, it was very easy to implement, but guess I was too frustrated last night to see the answer before me.

      FWIW, using QIDs so that others can create/maintain reports to be shown in a JS app without the involvement of developers. Thanks again!

      ------------------------------
      Shane Davis
      ------------------------------