Forum Discussion
WilliamEvans1
7 years agoQrew Cadet
I have one more quick question :) -
With the Javascript code below, If i set "How many months to copy to?" = 12... then it only works when Month = 1 (January) as it stops when it hits december (12) ...
Can you please let me know how to modify it so that if the initial month is another number (like 7 for July) and the Prompt is 12, then it should create months for 8, 9, 10, 11, 12, 1 , 2, 3, 4 , 5, 6 ... i.e. when it gets past 12 it starts at 1 again until the starting month value?
==============================================
// This is used by the button that duplicates an item many times
// Prompt for number of times to copy
var numMonths = prompt(" How many months to copy? enter 12 for whole year", 12);
//this is the starting month from Quickbase - i.e. 7 for July
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 - 1 && 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);
}
EDIT: I posted this as a seperate question, which is better worded, so it get's seen: https://community.quickbase.com/quickbase/topics/javascript-code-for-loop-calculation-help?rfm=1&.
With the Javascript code below, If i set "How many months to copy to?" = 12... then it only works when Month = 1 (January) as it stops when it hits december (12) ...
Can you please let me know how to modify it so that if the initial month is another number (like 7 for July) and the Prompt is 12, then it should create months for 8, 9, 10, 11, 12, 1 , 2, 3, 4 , 5, 6 ... i.e. when it gets past 12 it starts at 1 again until the starting month value?
==============================================
// This is used by the button that duplicates an item many times
// Prompt for number of times to copy
var numMonths = prompt(" How many months to copy? enter 12 for whole year", 12);
//this is the starting month from Quickbase - i.e. 7 for July
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 - 1 && 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);
}
EDIT: I posted this as a seperate question, which is better worded, so it get's seen: https://community.quickbase.com/quickbase/topics/javascript-code-for-loop-calculation-help?rfm=1&.