Multiple JSA=1 Responses from AJAX & API

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered
Hello community,

Has anyone else come across the issue of having multiple GenResultsTable API calls with JSA set to 1.

When using multiple GRT api calls, the Javascript array that is returned contains variables that other get overridden?

Has anyone come up with a solution for handling the multiple JSA responses?
Photo of B

B

  • 20 Points

Posted 4 years ago

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

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
Calling API_GenResultsTable&jsa=1 loads a script that creates a {set} of global variables including qdb_data. You have to immediately cache this to another variable or it will get clobbered when the next  API_GenResultsTable response arrives.


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


Well I hit my goal of reaching 400 pasties today so I am going to quit answering questions and go back to watching cartoons for the rest of the day.

Note that AJAX calls are asynchronous so under some conditions the responses could arrive out of the expected order. For example if the first request has a large response the response to the second request may arrive first. So you might want to chain your calls if using API_GenResutlsTable&jsa=1
Photo of B

B

  • 20 Points
Weird, I tried changing the variables in the Promise as well as trying to change them in the $.ajax success callback.   Jeez, when is QB gonna get with the times and return a JSON object?  I will give it another try.

Enjoy the cartoons!  I wish I was home watching some cartoons right now.  My fav is Pro Stars, the 90's cartoon  with Wayne Gretzky, Bo Jackson and MJ.
Photo of B

B

  • 20 Points
No luck, this technique did not work.  I tried caching the variables in the Promise, in the $.Ajax and outside of any function with it producing the same results in each method.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
> ... did not work

What are the specific results? What did not work? What is the code? I am out of here for the day.
Photo of B

B

  • 20 Points
I will spare you and your eyes from bleeding by including just the relevant info.  Basically, I run a console.log on each new "cached" variable, each console.log produces the same array.


 // 4. Create Promises using $.get
                var firmingpromise = $.get(jobsDB, firmData);
                var closingpromise = $.get(jobsDB, closeData);

/* <><><><><><><><><><><>< PROMISE 1 - Closing Date Report  <><><><><><><><><><><>< */

// 5. Init the Promise Functions using WHEN
                $.when(closingpromise).then(function () {

                    ///////////////////////////////////////////////////////////////////////////////////////////

                    var qdb_numcols1 = qdb_numcols;
                    var qdb_numrows1 = qdb_numrows;
                    var qdb_heading1 = qdb_heading;
                    var qdb_data1 = qdb_data;
                    console.log(qdb_heading1);

                   ///////////////////////////////////////////////////////////////////////////////////////////

                  ....Blah Blah Blah

// 7. Append to DOM
                    $('#closing').append(ftb);
                   
                }); //end promise
 /* <><><><><><><><><><><><><><><><><>< PROMISE 1 - END  <><><><><><><><><><><><<><><<><>< */
 

 /* <><><><><><><><><><><><>< PROMISE 2 - Actual Firming Date  <><><><><><><><><><><<><>< */
                $.when(firmingpromise).then(function () {

                    var qdb_numcols2 = qdb_numcols;
                    var qdb_numrows2 = qdb_numrows;
                    var qdb_heading2 = qdb_heading;
                    var qdb_data2 = qdb_data;
                    console.log(qdb_heading2);
                   
                  ....Blah Blah Blah

// 7. Append to DOM
                    $('#firming').append(ftb2);

                }); //end promise
 /* <><><><><><><><><><><><><><><><><>< PROMISE 2 - END  <><><><><><><><><><><><<><><<><>< */
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
>I will spare you and your eyes from bleeding by including just the relevant info.

Regarding your code:

var firmingpromise = $.get(jobsDB, firmData);
var closingpromise = $.get(jobsDB, closeData);

My non-bleeding eyes can't see the UR (jobsDB) or settings (firmData, closeData) that you are calling the $.get() with. Moreover, you should be calling $.getScript() if using API_GenResultsTable with &jsa=1.
Photo of B

B

  • 20 Points
The URL is a static string of the DB. I normally use the getReqDB variable if I am scripting inside the table, but I am scripting a custom reporting page.  Basically, the user completes a few inputs fields and a bunch of reports spit out (using the JS array that is returned).

var firmData = {
                    act: "API_GenResultsTable",
                    query: "{184.EX." + jobnumber + "}AND{281.GT." + date1 + "}AND{281.LT." + date2 + "}",
                    clist: "6.28.281.133",
                    jsa: "1"
                };
 
 var closeData = {
                    act: "API_GenResultsTable",
                    query: "{184.EX." + jobnumber + "}AND{14.GT." + date1 + "}AND{14.LT." + date2 + "}",
                    clist: "6.28.14.265",
                    jsa: "1"
                };

Have you ever worked with the XMLtoJSON.js script?  

I guess I could just do a DoQuery and parse the XML.  Reason I am not currently doing this is I am not too fluent in handling XML with Jquery.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
>I guess I could just do a DoQuery and parse the XML.  Reason I am not currently doing this is I am not too fluent in handling XML with Jquery.

Use the technique in this pastie to return JSON from your AJAX request:

https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=395
There is additional information in the forum posting which is linked from the pastie.
>Have you ever worked with the XMLtoJSON.js script?  
For a lot  of different reasons, general purpose XML to JSON conversion scripts do not work very well with QuickBase.
Photo of B

B

  • 20 Points
wow, thanks that was fast.  You sir, are a gentleman and a scholar.

Question:  Are you human or some kind of super intelligent cybernetic organism made by Cyberdyne Systems?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
Try this code:

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

Pastie
http://pastie.org/10266204


I renamed your variables to have Hungarian prefixes (eg dbid*, args*, etc) and lowerCamelCase names (eg jobNumber).

The tricky part of the code is accessing the JSON through these references:

argsFirming[0]

argsClosing[0]
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
I just landed on your planet and my saucer broke so I am stuck here. In my native multiverse QuickBase technology is more evolved and children learn JavaScript before entering Kindergarten.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
I just noticed that my function XMLFlatToObj returned an array instead of an object.

  return {records: data};


Fixed in pastie record.
Photo of B

B

  • 20 Points
you are human after all.

So how does one insert HTML code in these here comment boxes?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
You can't. You have to convert the comment to an answer.
Photo of B

B

  • 20 Points
Bummer.  I guess I will save my He-Man animated gifs for when I can answer one of your questions.......which will be never.  Unless you have questions about how to get woman to avoid you.  That seems to be my wheel house.