Forum Discussion
_anomDiebolt_
8 years agoQrew Elite
The problem is with the $.get(dbidSOW) call executing before $.get(dbidWR) returns its response.
To use a metaphor, you can think of a promise as a bakery claim check for the purchase of some bread at the bakery counter. If you grab a claim check you will eventually get to purchase your bread. But you can go on to do other work such as gab on the phone or discipline your child while waiting.
When you create a promise by making an AJAX call you are arranging to receive an XML response at some time in the future when it arrives. But the code keeps executing the next statements. So you wind up launching a second AJAX request without knowing the newly created [Record ID#] (ie WRid).
You can patch up the code like this (I added some console statements to debug):
This isn't the best way to structure the code because your are nesting AJAX calls rather chaining them with then(). But there is a bug the version of jQuery that QuickBase uses so this is acceptable for now.
Great article explaining these concepts:
The Promise of a Burger Party
https://kosamari.com/notes/the-promise-of-a-burger-party
To use a metaphor, you can think of a promise as a bakery claim check for the purchase of some bread at the bakery counter. If you grab a claim check you will eventually get to purchase your bread. But you can go on to do other work such as gab on the phone or discipline your child while waiting.
When you create a promise by making an AJAX call you are arranging to receive an XML response at some time in the future when it arrives. But the code keeps executing the next statements. So you wind up launching a second AJAX request without knowing the newly created [Record ID#] (ie WRid).
You can patch up the code like this (I added some console statements to debug):
var dbidSOW = "dbidSOW";
var dbidWR = "dbidWR"
var apptoken = "Myapptoken";
$.ajaxSetup({data: {apptoken: apptoken}});
$.get(dbidWR, {
act: "API_AddRecord",
_fid_48: F72,
_fid_132: F77,
_fid_7: F120,
_fid_147: F84,
_fid_77: F100
}).then(function(xml) {
console.dirxml(xml);
var WRrid = $("rid", xml).text();
console.log(WRrid);
$.get(dbidSOW, {
act. "API_EditRecord",
rid: F3,
_fid_114: WRrid
}).then(function(xml) {
console.dirxml(xml);
//document.location.href = ...
});
});
This isn't the best way to structure the code because your are nesting AJAX calls rather chaining them with then(). But there is a bug the version of jQuery that QuickBase uses so this is acceptable for now.
Great article explaining these concepts:
The Promise of a Burger Party
https://kosamari.com/notes/the-promise-of-a-burger-party