Discussions

Expand all | Collapse all

API_DOQUERY Javascript is not working

Shankar Ravi12-01-2016 06:04

_anom Diebolt)12-01-2016 06:20

  • 1.  API_DOQUERY Javascript is not working

    Posted 09-12-2016 13:09

    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



  • 2.  RE: API_DOQUERY Javascript is not working

    Posted 12-01-2016 05:40
    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.


  • 3.  RE: API_DOQUERY Javascript is not working

    Posted 12-01-2016 05:44
    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";
    });
    });


  • 4.  RE: API_DOQUERY Javascript is not working

    Posted 12-01-2016 05:47
    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);
    });


  • 5.  RE: API_DOQUERY Javascript is not working

    Posted 12-01-2016 05:51
    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.


  • 6.  RE: API_DOQUERY Javascript is not working

    Posted 12-01-2016 05:57
    Ok Then should I use chained version? Is that asynchronous method?


  • 7.  RE: API_DOQUERY Javascript is not working

    Posted 12-01-2016 05:59
    Both of my versions are asynchronous. I have not written a synchronous script is a decade!


  • 8.  RE: API_DOQUERY Javascript is not working

    Posted 12-01-2016 06:04
    Thanks for your suggestion.


  • 9.  RE: API_DOQUERY Javascript is not working

    Posted 12-01-2016 06:15
    If I just remove $.ajaxSetup({async: false}); from my script then will my code become asynchronous?


  • 10.  RE: API_DOQUERY Javascript is not working

    Posted 12-01-2016 06:20
    Yes


  • 11.  RE: API_DOQUERY Javascript is not working

    Posted 05-12-2018 03:11
    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);
    });


  • 12.  RE: API_DOQUERY Javascript is not working

    Posted 05-12-2018 03:22
    It is better to ask a new question with your specific details.

    The first thing I noticed is that you have QBU_key as a literal substing:
    query: "{3.EX.QBU_key}",
    You should be string concatenation like so:
    query: "{3.EX." + QBU_key+ "}",
    Or string interpolation:
    query: '{3.EX.${QBU_key}}',
    But in any case you don't say where the variable QBU_key is coming from.


  • 13.  RE: API_DOQUERY Javascript is not working

    Posted 05-12-2018 03:25
    The js code executes on a button click... But that first thing you noticed actually solved it! Thanks!
    "javascript:" &
            "var QBU_key = '" & [Record ID#] & "';" &
            "$.getScript(gReqAppDBID + '?a=dbpage&pagename=ADDBID.js');" &
            "void(0);"


  • 14.  RE: API_DOQUERY Javascript is not working

    Posted 05-25-2018 14:08
    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);
    });


  • 15.  RE: API_DOQUERY Javascript is not working

    Posted 05-26-2018 16:14
    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.