Forum Discussion
RyanSolutions
8 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);
}
- WilliamEvans17 years agoQrew CadetIt's a year later, but thanks so much for this, I managed to get it to work
Here's my modifications to your code in case this helps someone one day
CODE PAGE: DuplicateItemMonthly.jsvar numMonths = prompt("For how many months do you want to duplicate this item?", 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 + commonfields + "&_fid_43=" + nextMonth;
xhttp.open("GET", myAPI, false);
xhttp.send();
nextMonth += 1;
}
}
location.reload();
}
catch(e){
console.log("Unexpected Error: " + e);
}
BUTTON CODE:var text commonfields = ToText(
"&_fid_8=" & [Budget Status Flag]
& "&_fid_22=" & URLEncode([Comments])
& "&_fid_25=" & [Account Code]
& "&_fid_28=" & [Related Company]
& "&_fid_244=" & [Item Status]
& "&_fid_72=" & [General Cost Currency]
& "&_fid_73=" & URLEncode([General Cost Description])
& "&_fid_122=" & [People Cost Number of Days Required]
& "&_fid_156=" & URLEncode([Item Vendor])
& "&_fid_160=" & [Spend Country]
& "&_fid_9=" & [Recoverable?]
& "&_fid_165=" & [General Cost Quantity]
& "&_fid_164=" & [Predefined Daily Cost Quantity]
& "&_fid_163=" & [Predefined Cost Quantity Completed]
& "&_fid_114=" & [Related People Cost]
& "&_fid_81=" & [Predefined Daily Cost Days]
& "&_fid_71=" & [General Unit Cost]
& "&_fid_69=" & [Related Predefined Daily Cost]
& "&_fid_68=" & [Related Predefined Cost]
& "&_fid_37=" & [Related Fx]
& "&_fid_32=" & [Item Type]
& "&_fid_47=" & [Related Sub-Project]
& "&_fid_241=" & URLEncode([Original Item Project Category])
& "&_fid_305=" & [Item has been Deferred]
& "&_fid_302=" & [Select Month For Split]
& "&_fid_299=" & [People Cost # Days to DEFER]
& "&_fid_296=" & [Predefined Daily Cost Qty to DEFER]
& "&_fid_295=" & [Predefined Daily Cost # of Days to DEFER]
& "&_fid_294=" & [Predefined Daily Cost Days / Qty]
& "&_fid_292=" & [Predefined Cost Quantity to DEFER]
& "&_fid_281=" & [General New Split Qty to DEFER]
& "&_fid_280=" & [General New Split Unit Cost to DEFER]
& "&_fid_279=" & [General Split Cost / Qty?]
& "&_fid_259=" & [Item Completion Status]);
var text apptoken = "MY APP ID";
var text addItem = ToText(URLRoot() & "db/" & "MY TABLE ID" & "?a=API_AddRecord&apptoken=" & $apptoken);
var text itemMonth = ToText([Month Number]);
"javascript:var addItem='" & $addItem & "';var itemMonth='" & $itemMonth & "';var commonfields='" & $commonfields & "';$.getScript(gReqAppDBID + '?a=dbpage&pagename=DuplicateItemMonthly.js');void(0);"