I’m trying to debug a Console error I’m getting for one particular user.
This is the error message we are getting
The code:
function createCopies(){
//loading
if(validateForm()){
console.log("form validated")
loadingStart();
var copies_obj = {};
copies_obj.number = document.getElementById("copies_number").value == "" ? 1 : document.getElementById("copies_number").value;
console.log("copies # " + copies_obj.number)
google.script.run.withSuccessHandler(function(res){
document.getElementById("save-success-message").classList.remove("invisible");
setTimeout(function(){
document.getElementById("save-success-message").classList.add("invisible");
}, 4000);
//done loading
loadingEnd();
}).replicateTemplate(copies_obj);
}else{
$('#errorNotification').toast('show');
}
}
Function that is being called
function replicateTemplate(copies_obj) {
//JE Copies Reference Sheet. Put the information on the first Sheet found.
//If we add sheets to this Spreadsheet lets add them to the right side.
var template_list_sheets = SpreadsheetApp.openById(template_list).getSheets();
var template_list_sheet_0 = template_list_sheets[0];
//Start looping to create the X number of copies
Logger.log("copies #: " + copies_obj.number)
for(var i = 0; i < copies_obj.number; i++){
var template_date = Utilities.formatDate(new Date(), SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "MM/dd/yyyy hh:mm:ss")
var template_list_rows = template_list_sheet_0.getLastRow();
var fe_destination_folder = DriveApp.getFolderById(fe_folder);
var be_destination_folder = DriveApp.getFolderById(be_folder);
//1. Make a copy of the original template; save the original name & get the newly create template id
var original_fe_template = DriveApp.getFileById(fe_template);
var fe_template_name = original_fe_template.getName();
var new_fe_template = original_fe_template.makeCopy().getId();
//2. Grab the newly created template, get its url and rename the file
var new_fe_file = DriveApp.getFileById(new_fe_template);
var new_fe_url = new_fe_file.getUrl();
new_fe_file.setName(fe_template_name.replace("###",template_list_rows));
//3. Repeat for BE Template
var original_be_template = DriveApp.getFileById(be_template);
var be_template_name = original_be_template.getName();
var new_be_template = original_be_template.makeCopy().getId();
var new_be_file = DriveApp.getFileById(new_be_template)
var new_be_url = new_be_file.getUrl();
new_be_file.setName(be_template_name.replace("###",template_list_rows));
//4. Update the Named Ranges
SpreadsheetApp.openById(new_fe_template).getRangeByName("BELink").setValue(new_be_url);
SpreadsheetApp.openById(new_be_template).getRangeByName("FELink").setValue(new_fe_url);
SpreadsheetApp.openById(new_be_template).getRangeByName("CopyNumber").setValue(template_list_rows);
//5. Once the files are done, move them to the destination folder
DriveApp.getFileById(new_fe_template).moveTo(fe_destination_folder);
DriveApp.getFileById(new_be_template).moveTo(be_destination_folder);
//6. Add the files URL into the Reference Sheet
var new_row = [template_list_rows, template_date, new_fe_url, new_be_url];
template_list_sheets[0].appendRow(new_row);
}
}
At this point I’m not really sure where to dig in order to diagnose what is wrong.
We have tested the same script with other users without any issue, but the error message doesn’t give us any clear clue.
Note: The user has access to all the files used during the script execution