Problem
I have the following script. What it does when triggered manually is :
- Creating new sheets with the name of each person in column A
- Adding a row in the newly created sheet with the data of columns A and B
- Other stuff with no impact on the problem below
When I set the built-in trigger, it simply doesn't work.
What I already tested
What is important to know in my opinion is that the data in column A and B in this spreadsheet is imported thanks to another script in another spreadsheet. Why is it important ? Because if I set a built-in trigger on change or edit and I add a row manually, it triggers my built-in trigger as perfectly as when I trigger it manually.
Conditions
Last thing to explain, I don't want a "solution" that forces me to make a manual action to make it work. I need it to work automatically, not with some kind of checkbox or something.
Does anyone could have a solution for this problem ? A huge thanks in advance to help me solve this issue.
Code
function createNewSheets() {
// 1. Retrieve the current sheet names.
var dataSheet = SpreadsheetApp.getActiveSpreadsheet();
var sheetNames = dataSheet.getSheets().map(s => s.getSheetName());
// 2. Retrieve the values from "mastersheet" sheet.
var masterSheet = dataSheet.getSheetByName('Liste de nageurs');
var values = masterSheet.getRange('A2:B' + masterSheet.getLastRow()).getValues();
// Imports table from link
var swimmerTable = '=IMPORTHTML(B1;"table";4)'
// Concatenates event with pool size
var fullName = 'CONCATENATE(C2;" - ";D2)'
// 3. Using the retrieved sheet names and values, the new sheets are inserted and the values are put.
values.forEach(r => {
if (!sheetNames.includes(r[0])) {
var newSheet = dataSheet.insertSheet(r[0])
sheetNames.push(r[0]);
newSheet.appendRow(r);
// Sets the formula in the 3rd column:
newSheet.getRange(1, 3).setFormula(swimmerTable)
// Sets the formula2 and iterates it from row 2 to row 50
newSheet.getRange("J2:J50").setFormula(fullName)
}
});
}
What is important to know in my opinion is that the data in column A and B in this spreadsheet is imported thanks to another script in another spreadsheet., can you provide this current script? 2. What is the script ofcreateNewSheets()? - TanaikeSpreadsheetApp, as a workaround, when the script is used with Sheets API, OnChange trigger can be used. Or, as another workaround, I think that when the script for putting to Spreadsheet is run, the another function you want to run can be run by the running function. So I asked about the script for putting the values to Spreadsheet. By confirming your script, I would like to propose the modified script. - Tanaike