I am trying to copy a value from the active spreadsheet to another spreadsheet using setValue. Running the script with the line (setValue) just after the comment raises the execution time with more than 10 seconds, compared to when i run it without setting the value of the selected range. Any idea why this is happening ?
function projectionNewProj(){
const sourceSpreadsheet = SpreadsheetApp.getActive();
const projection_sheet = SpreadsheetApp.openById("dazMV23sKvnFeFR2jba17gaUKsg8").getSheetByName("Projections Master");
const active_sheet = sourceSpreadsheet.getActiveSheet();
const active_row = active_sheet.getActiveCell().getRow();
const proj_id = active_sheet.getRange(active_row,1).getValue();
var ui = SpreadsheetApp.getUi();
if (active_sheet.getName()=="Client List" && active_row > 1 && proj_id != "") {
const pm = active_sheet.getRange(active_row,11).getValue();
if (pm !==""){
const client_name = active_sheet.getRange(active_row,2).getValue();
client_indice = projection_sheet.getRange("A14:A").createTextFinder(client_name).matchEntireCell(true).findAll();
if (client_indice.length != 0){
proj_indice = projection_sheet.getRange("B14:B").createTextFinder(proj_id).matchEntireCell(true).findNext();
if (proj_indice == null){
const ins_row = client_indice.pop().getRow();
projection_sheet.insertRowAfter(ins_row);
const rowin = projection_sheet.getRange(ins_row+1, 2);
// The following line adds more than 10 seconds !
rowin.setValue(1254);
}else{
ui.alert("This Project already exists");
}
}else{
ui.alert("Client Name does not exist in the Projections Sheet");
}
}else{
ui.alert("Please select a Project manager");
}
}else{
ui.alert("Please select a non-empty project row in Client List Sheet");
}