Skip to main content
Question

Async concept question with API_DeleteRecord

  • July 11, 2018
  • 0 replies
  • 74 views

I have a concept question pertaining to API_DeleteRecord, although could be said for any API call.

Let's say I have a really basic script

for (var i = 0; i < 5; i++){       $.get(url,           act: "API_DeleteRecord",           rid: i       );
}

Would it even be necessary to use async/await for this to execute successfully? Does the server allow several ajax requests at once?
This topic has been closed for replies.

  • Registered
  • July 11, 2018
Tip of the hat! This is the best question asked all year.

First, you have to realize that most of the applications of using JavaScript with QuickBase are workarounds and they may well embrace tricks, shortcuts, assumptions or goals that you would not use if you were developing a solution from scratch where you could control all technical aspects of the solution.

So the simplest solution to using your code as you wrote it would be to just make all jQuery AJAX calls synchronous by adding this line of code:
$.ajaxSetup({async: false});
And maybe add a spinner to indicate there are AJAX calls in flight:
$.ajaxSetup({async: false}); 
$("<img>", {
  src: "https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif",
  id: "QBU_Spinner"
}).css({
  position: "fixed",
  top: "50%",
  left: "50%",
  transform: "translate(-50%, -50%)"
}).appendTo("body");
for (var i = 0; i < 5; i++) {
  $.get(url,
    act: "API_DeleteRecord",
    rid: i
  );
}
$("#QBU_Spinner").hide();

My professional colleagues would be aghast that I just suggested that you could use synchronous AJAX calls because asynchronous calls are all but the norm for most greenfield development.

Use it if you want, but there is good reason to master asynchronous programming as it will greatly expand your understanding of the process and propel you to even greater capabilities of what can be achieved using script with QuickBase.

  • Author
  • Registered
  • July 11, 2018
I am refactoring my code to accomodate async. I was using async/await to handle each API_DeleteRecord call, but I'm still not completely clear. You're saying turning async off will make this code snippet work, but does this imply quickbase doesn't handle several ajax requests made at *basically* the same time/ does quickbase handle all the requests as a queue? I know that ajax calls are event based, does one event get completely interrupted by another?

Obviously my goal is to write optimized code because our list gets quite large and there are specifications for what gets deleted, I would preferably like to delete these records with async