How can I use API_GenResultsTable and a dropdown list to embed a report into a table's form?

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered
I have the following setup in a sales app.

Orders -- > Order Line Items <-- Products <-- Product Types

I want to embed a report into the Orders main form that displays all Products of a certain Product Type based on the selection in a dropdown list. I am trying to use API_GenResultsTable, but for some reason it is displaying the resulting qdbWrite(); response on top of all of the other form information. I check the source code of the page, and I can see that everything is there but hidden. I have the URL generating on DDL change just fine, I just can't get the table results to render correctly. Any ideas?

    $(function () {
        $("#_fid_98").change(function () {
            var selectedText = $(this).find("option:selected").text();
            var selectedValue = $(this).val();
            alert("Selected Text: " + selectedText + " Value: " + selectedValue);

var url = "https://company.quickbase.com/db/&quot;;
url += "dbid";
url += "?act=API_GenResultsTable";
url += "&dvqid=7";
url += "&query={29.TV.";
url += encodeURIComponent(selectedValue);
url += "}";
url += "&jht=n";

var promise = $.getScript(url);

$.when(promise).then(function() {
 
  qdbWrite();

            });
        });
    });


I have also tried $("#potential").load(url); to try to load it to the DIV ID in my IOL field, but then it writes out plain javascript, granted it's now in the form and not on top of it, which seems like progress, but then if I wrap it in <script> tags, it reverts to displaying on top of the rest of the form. I feel like I am missing something simple here, and I am sure I will bang my head when it is solved. Thanks in advance!
Photo of Dana

Dana

  • 0 Points

Posted 4 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
qdbWrite() uses document.write() to generate output. However, document.write() is a bit schizophrenic in that it acts one way if called during page load versus after the page is loaded. When called during page load document.write() adds its output to the page. When called after page load document.write() replaces the page content.
Photo of Dana

Dana

  • 0 Points
Interesting. Is there a way to use the built-in qdbWrite() functionality in a form or does this mean I should let it go and move on to the jsa=1 approach?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
use &jsa=1 and templating to generate the HTML.
Photo of Dana

Dana

  • 0 Points
I'm just now getting a chance to get back to this. Do you have an example of taking the JSA results and placing them in a template table? The results of the query will be a variable number of rows, and I would like to append one last column to each row because I am creating a custom URL button for that last column. I am not concerned with pretty so much as automated. It's disappointing to not be able to use the built-in qdbWrite() functionality.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
For an example visit this application:

Formula Functions Reference
https://www.quickbase.com/db/6ewwzuuj?a=q&qid=6

and paste the following code into the JavaScript console:

Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=459


Normally you pass an object to Mustache which consists of an array of other objects (perhaps recursively). But qdb_data returned by API_GenResultsTable&jsa returns an array of arrays. Mustache is flexible enough to handle this case but you have to refer to the properties using their array index instead of their object key.

Since this thread has wandered into templating with Mustache instead of using qdbWrite() I would start a new thread if you have further questions.
Photo of Dana

Dana

  • 0 Points
Gracias! Piece by piece I am getting this to come together. Out of curiosity, is there a way to remain on the Parent page when I execute my API_AddRecord link from the report table I generated? Past practice has been to throw an "rdr" on the end of the URL, but that doesn't seem like best practice. I would rather either execute the API_AddRecord in a pop-up/layer or execute and just stay on the page. I don't want my users to have to reload the page or re-select the dropdown value they were working with. Searching for a relevant question with this topic is proving challenging on the forum here.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
>Out of curiosity, is there a way to remain on the Parent page when I execute my API_AddRecord link from the report table I generated?

Calling the API using jQuery's AJAX methods ($.get(), $.post(), etc) will not reload the current page. However, you don't want to create a situation where your AJAX calls change the value of some field for which the current page is still  displaying the old value of the field.
Photo of Dana

Dana

  • 0 Points
Yeah, I was thinking of the pros/cons there, too. I am basically adding Children records to a Parent record, and the built-in embedded report will not be updated if I don't refresh the page.