Forum Discussion
RyanSolutions
9 years agoQrew Member
Unfortunately, to get around the timeout error JavaScript becomes necessary. I've put together a quick snippet of how the script may look using xhttp. Add a code page titled "MyScript.js" and copy your JavaScript into there. This code was quickly put together and has not been tested. You have been warned :-)
Its important you pay attention to the variables you are passing from Quick Base into the script itself. Quick Base variables are passed through the button (see below). The script receives a few variables (including the start month and part of the add record API call). Some useful resources on JavaScript can be found at https://www.w3schools.com.
// QuickBase Button
var text dbid = "Table ID goes here";
var text apptoken = "App token goes here";
var text addItem = ToText(URLRoot() & "db/" & $dbid & "?a=API_AddRecord&apptoken=" & $apptoken); // **NOTE: This is an incomplete statement.
var text itemMonth = ToText([Item Month]);
"<a class='Tall Vibrant Snowy'
href=\"javascript:var addItem='" & $addItem & "';var itemMonth='" & $itemMonth & "';$.getScript(gReqAppDBID + '?a=dbpage&pagename=MyScript.js');void(0);\">Recurring TTI</a>"
// Sample JavaScript
var numMonths = prompt("How many items do you want to add?", 1);
var monthStart = parseInt(itemMonth, 10);
var nextMonth = monthStart + 1;
var xhttp;
try{
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
}
else {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if(numMonths > 0 && numMonths < 13){
for(var i = 0; i <= numMonths && $nextMonth < 13; i++){
myAPI = addItem + "&_fid_1=" + nextMonth;
xhttp.open("GET", myAPI, false);
xhttp.send();
nextMonth += 1;
}
}
location.reload();
}
catch(e){
console.log("Unexpected Error: " + e);
}
Its important you pay attention to the variables you are passing from Quick Base into the script itself. Quick Base variables are passed through the button (see below). The script receives a few variables (including the start month and part of the add record API call). Some useful resources on JavaScript can be found at https://www.w3schools.com.
// QuickBase Button
var text dbid = "Table ID goes here";
var text apptoken = "App token goes here";
var text addItem = ToText(URLRoot() & "db/" & $dbid & "?a=API_AddRecord&apptoken=" & $apptoken); // **NOTE: This is an incomplete statement.
var text itemMonth = ToText([Item Month]);
"<a class='Tall Vibrant Snowy'
href=\"javascript:var addItem='" & $addItem & "';var itemMonth='" & $itemMonth & "';$.getScript(gReqAppDBID + '?a=dbpage&pagename=MyScript.js');void(0);\">Recurring TTI</a>"
// Sample JavaScript
var numMonths = prompt("How many items do you want to add?", 1);
var monthStart = parseInt(itemMonth, 10);
var nextMonth = monthStart + 1;
var xhttp;
try{
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
}
else {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if(numMonths > 0 && numMonths < 13){
for(var i = 0; i <= numMonths && $nextMonth < 13; i++){
myAPI = addItem + "&_fid_1=" + nextMonth;
xhttp.open("GET", myAPI, false);
xhttp.send();
nextMonth += 1;
}
}
location.reload();
}
catch(e){
console.log("Unexpected Error: " + e);
}