Creating a new sheet in Google Sheets and renaming new sheet

You do not show your web component blocks for the addSheet function ?

The actual function needs to be outside of the doGet(e) / doPost(e) (whichever you are using), but the if statement does need to be in it.

Ooops didn't realize I'd need web blocks. Then again in hindsight it makes sense. (Sorry still learning)

So I fiddled about with it hoping I might be doing the right thing or at least heading in the right direction, but it seems not.

Blocks add2

This is what I've added to the current blocks in the hopes that this might in some way work. Not sure really if I've done this correctly.

image

needs to be &SHEETNAME2= swap the ? for an &

and of course you will need to add a Web1.GET block to actually send the data :wink:

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.

Hi Seniors,
Also want a new sheet with in the spreadsheet. followed above steps but not success.
kindly guide.

Either an issue with your script, blocks or spreadsheet. Show everything, and check all of this first:

Hi TIMAI2,
good day...!

can you make block for me. using this script

SCRIPT

function doGet(e) {
  var spreadsheet = SpreadsheetApp.openById('<YOUR SHEET ID HERE>');
  var newSheet = spreadsheet.insertSheet();
  return ContentService.createTextOutput('Created a new sheet: ' + newSheet.getName());
}

BLOCKS

image

thanks, need blocks for below mentioned script
image

What have you tried ?

I have created 3 buttons.

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)

Please show your relevant blocks and google apps script...

It sounds like you need to be setting the correct sheetname in your get url

var newSheetName = "";

function doPost(e) {
  var action = e.parameter.action;
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");

  if (action == "createSheet") {
    var newSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet();
    var range = sheet.getDataRange();
    range.copyTo(newSheet.getRange(range.getA1Notation()));
    newSheetName = newSheet.getName();
    return ContentService.createTextOutput(newSheetName);
  } else if (action == "pasteValue") {
    var sheetName = e.parameter.sheetName;
    var newSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
    newSheet.getRange('A33').setValue(e.parameter.value);
    return ContentService.createTextOutput("Value pasted");
  } else if (action == "getTableData") {
    var sheetName = e.parameter.sheetName;
    var newSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
    var range = newSheet.getRange('B2:D33');
    var values = range.getValues();
    return ContentService.createTextOutput(JSON.stringify(values));
  } else if (action == "deleteSheet") {
    var sheetName = e.parameter.sheetName;
    var sheetToDelete = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
    SpreadsheetApp.getActiveSpreadsheet().deleteSheet(sheetToDelete);
    return ContentService.createTextOutput("Sheet deleted");
  }
}

function doGet(e) {
  var sheetName = e.parameter.sheetName;
  var newSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
  var range = newSheet.getRange('B2:D33');
  var values = range.getValues();
  return ContentService.createTextOutput(JSON.stringify(values));
}

It would help to be able to see the full urls used in Script,Script2,Script3 and in the Clock Timer

Is there any data on the spreadsheet to begin with, on an existing sheet ? (before any new sheets are created). If so what is it?

Script1: https://script.google.com/macros/s/AKfycby2m0nsdeJwYMSjkwSss9qzDepKuge1_RcfZY2OkB5SAGkDOgZJoVXTB0g0wWv8KVry/exec?action=createSheet

Script2: https://script.google.com/macros/s/AKfycby2m0nsdeJwYMSjkwSss9qzDepKuge1_RcfZY2OkB5SAGkDOgZJoVXTB0g0wWv8KVry/exec?action=pasteValue&value=

Script3: https://script.google.com/macros/s/AKfycby2m0nsdeJwYMSjkwSss9qzDepKuge1_RcfZY2OkB5SAGkDOgZJoVXTB0g0wWv8KVry/exec?action=getTableData&sheetName=

Clock timer: 180000 https://script.google.com/macros/s/AKfycby2m0nsdeJwYMSjkwSss9qzDepKuge1_RcfZY2OkB5SAGkDOgZJoVXTB0g0wWv8KVry/exec?action=pasteValue&value=

Web2 get

Thank you. I will now get to work on this for you.

Why the empty column (A)?

image

Also what are you intending to post to "A33" ?

What is the reasoning behind the 3 minute clock timer ? Won't this cause an issue if the user leaves the app inside that time?

Your script should really not be hard coding ranges, you should be feeding these as parameters from your app.

user id is post from textbox1 in range "A33".

new created sheet auto deleted after 3 minutes

OK, but why 3 minutes, why not just delete it?

depends on internet speed from posting to read data. if here is another option that when user get / read data from new created sheet then sheet is deleted. guide me. but first challange is my post # 18 (button3)