Discussions

 View Only
  • 1.  Formula URL button using Javascript to display the count of records in a Table using API_DoQueryCount

    Posted 05-07-2019 13:47
    I want to display the count of records in a Table using API_DoQueryCount .
    I know this API will return response in the XML format. I want to process that XML in Javascript to extract the number of records. Also i want to write that JavaScript in a Formula URL Button.


  • 2.  RE: Formula URL button using Javascript to display the count of records in a Table using API_DoQueryCount

    Posted 05-07-2019 14:01
    You can write JS into a formula-url using the following syntax: 

    javascript: {
    //enter your code here
    }

    If you're trying to do a doQueryCount - you'll have to do a couple things
    1) Easiest method is to do a GET against your table using doQuery Count
    2) Parse the XML response to get the count
    3) Do another GET - this time an EditRecord call to store that value somewhere. So logging it as a record somewhere - or editing a field with the current count - your choice

    So like:

    javascript: {
    $.get(' url for doQueryCount ',function(data) {
         //parse the response
         $.get(' editRecord ')
    })
    }

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 3.  RE: Formula URL button using Javascript to display the count of records in a Table using API_DoQueryCount

    Posted 05-07-2019 16:40
    Hello Chayce, 
    Thanks for your reply.

    Can you please provide any sample code for that .


  • 4.  RE: Formula URL button using Javascript to display the count of records in a Table using API_DoQueryCount

    Posted 05-07-2019 17:11
    This should get you started hopefully - you'll need to swap out your own DBID and realm / apptoken info as appropriate

    var text urlD = "https://yourrealm.quickbase.com/db/dbid?a=API_DoQueryCount";
    var text urlE = "https://yourrealm.quickbase.com/db/dbid?a=API_EditRecord&rid=***&_fid_**=";

    "javascript: {" & 
      "$.get(' " & $urlD & "',function(data,success) {" & 
            "console.log(data);" &
            "var count = data.getElementsByTagName('numMatches')[0].innerHTML;" & 
            "console.log(count);" & 
            "$.get('" & $urlE & "' + count);" & 
      "});" &   
    "}"

    The gist - 

    Do your doQueryCount - store that value in a variable count
    Make another editRecord call - and pass in the variable count as part of the call

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 5.  RE: Formula URL button using Javascript to display the count of records in a Table using API_DoQueryCount

    Posted 05-08-2019 12:24
    Yes, I changed the urlD and urlE as per my tables and  i inserted the above code into my Formula URL Field. In the Field properties, i have selected "Display as button on forms and reports". Now on the form its is showing as a button but when i click on the button its not working. I mean its not clickable and it is not updating the count value to a field.

    My doubt here is that the output of Formula URL button should be a URL link. But here we are inserting Javascript code in the Formula URL which gives the output to be a JS Code instead of URL. I suspect it is the reason that the button is not working.


  • 6.  RE: Formula URL button using Javascript to display the count of records in a Table using API_DoQueryCount

    Posted 05-08-2019 12:36
    If you've copied it exactly as I've coded it above - it is likely working to some extent - but you may have a minor error somewhere. I can confirm that I tested the above in a test app of mine - and the output of a url button does not necessarily have to be a link. Have you opened up the network tab or the console in your browser to see if you are receiving any syntax or network issues? 

    Additionally - I didn't add anything to the above sample that would actually do anything visual on the screen. It only did the API Calls and then stopped. If you are looking for some kind of 'action' to occur - I would suggest a window.location.reload() so the page just refreshes. 

    So in the above - 
    "javascript: {" & 
      "$.get(' " & $urlD & "',function(data,success) {" & 
            "console.log(data);" &
            "var count = data.getElementsByTagName('numMatches')[0].innerHTML;" & 
            "console.log(count);" & 
            "$.get('" & $urlE & "' + count,function(data,success) {" & 
                 "window.location.reload();" & 
             }); & 
      "});" &   
    "}"

    Something like that should work

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 7.  RE: Formula URL button using Javascript to display the count of records in a Table using API_DoQueryCount

    Posted 05-09-2019 17:30
    Yes,
    Its working but the URL of API_DoQueryCount contains single quotes within the URL . It causes the error. So, i replaced with double quotes and by using ESCAPE CHARACTER(\). After that it worked fine.

    Thank you..



  • 8.  RE: Formula URL button using Javascript to display the count of records in a Table using API_DoQueryCount

    Posted 05-09-2019 17:31
    Great. Glad it worked out

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base