1
votes

I set up some code to copy and paste a certain value from the formula using form submissions as a trigger. It worked! But now it's giving me a "too many simultaneous invocations" error with reference to line 3.

It has not been called in excess of 20 times a day (as I know is the set limit) so I'm imagining I did something off with my code... (I'm NOT a JS guy.)

function pasteValue(){
var sheet = 
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('INVOICES')
var lastRow = sheet.getDataRange().getValues();

lastRow.forEach(function (row,index) {
    if (row[1] == "") {  
        lastRow.length = index;
    }
});

var newRange = sheet.getRange(lastRow.length,13);
newRange.copyTo(newRange, {contentsOnly: true})
sheet.setActiveRange(newRange);
}
1
Why are you copying the range to itself ? "newRange.copyTo(newRange, {contentsOnly: true})"filipe
On form submission, there are calculations being made off of a variable percentage which changes over time). I want to record exactly what it was at the time of submission so I'm having the formula pasted as a value.Joshua Smith
Try adding SpreadsheetApp.flush()TheMaster

1 Answers

1
votes

If what you want is to remove the formulas, its more straightforward to do something like this with "display values":

function pasteValue(){
var sheet = 
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('INVOICES')
var data = sheet.getDataRange().getDisplayValues();
sheet.getRange(1, 1,data.length, data[0].length).setValues(data);
}