Forum Discussion

AlvaroGuerrero's avatar
AlvaroGuerrero
Qrew Member
9 years ago

API_DOQUERY Javascript is not working

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

14 Replies

  • ChadBrandmire's avatar
    ChadBrandmire
    Qrew Assistant Captain
    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);
    });
  • 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.