Forum Discussion

ArchiveUser's avatar
ArchiveUser
Qrew Captain
8 years ago

query using a variable in html page

<script>
var a=1594;
console.log(a)
</script>
<script lang="javascript" src="https://tsemerge.quickbase.com/db/
DBID?a=API_GenResultsTable&apptoken=APPTOKEN&jht=1&query={'29'.EX.+'a'}AND{'6'.XEX.''}AND{'7'.EX.''}OR{'7'.AF.'today'}&clist=30.20.14.6.7.8&slist=6&options=sortorder-A">


How would {'29'.EX.+'a'} this statement work? I want a to be kRid eventually.
  • This is how I would do it. note you can wrap URL in a var or just use the DBID if used within the app. 

    var query= "{'29'.EX.'" + kRid + "'}AND{'6'.XEX.''}AND{'7'.EX.''}OR{'7'.AF.'today'}";

     $.get(DBID, {
                            act: "API_GenResultsTable",
                            query:query,
                            clist:"30.20.14.6.7.8",
                            slist: "6",
                            options:"sortorder-A"
                        }, function(xml) {

                            $("#results").html(xml)
                        })
    • ChuckGrigsby's avatar
      ChuckGrigsby
      Qrew Cadet
      That should be fine. Just use the script tags like you did if you need to. Just change the #results to whatever element you want the report to display.
    • ArchiveUser's avatar
      ArchiveUser
      Qrew Captain
      That is not really working for me, there is no way to include a here {'29'.EX.+'a'}?
    • ChuckGrigsby's avatar
      ChuckGrigsby
      Qrew Cadet
      Feel free to reach out if you want to go through a demo of one my HTML pages. Which is loaded on dashboards but could be loaded anywhere. But you would need to get your values for your variables then change the source. I don't think you can enter a variable in the source URL. 

      chuck@chuck.support
  • You are not going to be able to dynamically set the src of a script tag that references ?act=API_GenResultsTable&jht=1. This is because that script file references document.write() and that method operates differently between when it is called on initial page load and when it is called later.

    Moreover, nobody uses  document.write() anymore. It is archaic construct left over from the early days of the web and is only used for some obscure edge cases related to having a backup for a missing CDN file. If you are writing your own code page and want to use ?act=API_GenResultsTable call it with &jsa=1 instead and generate your report using a template such as Mustache. Search for API_GenResultsTable and Mustache for historic examples and I think you will find material you can adopt.