I've been trying to get my app to create a new sheet in a Google sheet, but for the life of me I can't seem to get it to run/trigger. Not really sure what I'm doing wrong but I think that it's not triggering correctly from the AI2. I've tried so many different way to implement this that I'm really not sure which direction to go.
OK, so here is what I would like to happen:
I'm currently using TIMAI2's fix for HK's CRUD app. Now I would like to add additional information to a selected ID. The selection is made from the listview containing the different IDs. So my idea is/was that the user selects the ID they want to add the additional info to and clicks on a button Add ADD. info - this opens to a new arrangement where additional info can be entered. Upon opening the new arrangement a new sheet needs to be created in the spreadsheet so that this additional info can be re-called at a later stage. The new sheet, I thought, could then also be renamed to the selected ID. eg. selected ID 001 - new sheet name 001.
Seeing as this might be way above my level I decided to first only have a new sheet be created, however unfortunately it is not.
I would really appreciate any assistance with this.
I apologize in advance for the simplistic nature of my script, after trying all of the "more advanced" methods I decided to try the simplest method as shown in the Google apps script references.
This apps script code I have previously used to create a new sheet(tab/grid) in an existing spreadsheet:
//insert a new grid, with name, to a specified sheet
function insertGridToSheet(name,sheetID) {
var ss = SpreadsheetApp.openById(sheetID);
var shs = ss.getSheets();
ss.insertSheet(name,shs.length + 1);
return ContentService.createTextOutput(name + ' added');
}
This function is called as follows:
//add new grid to sheet
if ( e.parameter.func == "newGridForSheet" ) {
return insertGridToSheet(e.parameter.name,e.parameter.sheetID);
}
you will need to supply:
The "func" selector
The spreadsheet ID
The name for the new sheet(tab/grid)
The new sheet(tab/grid) is placed as the last sheet(tab/grid)
Just a sort of follow up question. As explained above, I would like to have the new sheet/tab named after the selected ID. Using your HKFix app as an example, if I add a global variable SHEETNAME2 which has an empty text block, and I then set global SHEETNAME2 to ListView1 selection, and then reference SHEETNAME2 in the script code you just provided instead of 'name'. Would that change the new sheet/tab name to the selected list ID?
Thanks for the assistance, I've made your suggested changes. But unfortunately it is still not creating the new sheet. I suspect I'm still missing something somewhere.
function doGet(e) {
var spreadsheet = SpreadsheetApp.openById('<YOUR SHEET ID HERE>');
var newSheet = spreadsheet.insertSheet();
return ContentService.createTextOutput('Created a new sheet: ' + newSheet.getName());
}
Button1: insert new sheet + copy paste data from other sheet to new created sheet (range B2:D33)
Button2: post text in new created sheet (range A33) from Textbox1
And last Button3:
Get / read data from new created sheet.
All is done. But data read from active sheet not from new created sheet. Example active sheet is sheet3 and new created sheet is sheet4.
When I pressed button3 data read from active sheet (sheet3) instead of new created sheet (sheet4)