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?
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)?
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)
OK, let me see how you have it setup then I will also work on that.
@Faisal_Nazir : Just to let you know, I am working on this, it is a bit of a muddle, but hopefully there soon, need to do some testing...
Sure sir, I'll be waiting..
OK, if I have understood your requirements correctly, I provide a test aia project and a revised script. You only need a doGet(e) in your script, and some variables in your blocks to handle the data returns. I have set the new sheet to be deleted after it has been read and data displayed in the listview. You need to add your own script url to the aia project - just the one returned from deployment, without any parameters, the parameters are now included in the button blocks.
EXAMPLE AIA
faisal.aia (4.0 KB)
BLOCKS
SCRIPT
function doGet(e) {
var newSheet, newSheetName, sheetName, msg ;
var action = e.parameter.action;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName("Sheet1");
if (action == "createSheet") {
newSheet = ss.insertSheet();
var range = sh.getDataRange();
range.copyTo(newSheet.getRange(range.getA1Notation()));
newSheetName = newSheet.getName();
msg = newSheetName;
} else if (action == "pasteValue") {
sheetName = e.parameter.sheetName;
newSheet = ss.getSheetByName(sheetName);
newSheet.getRange('A33').setValue(e.parameter.value);
msg = "Value pasted";
} else if (action == "getTableData") {
sheetName = e.parameter.sheetName;
newSheet = ss.getSheetByName(sheetName);
var range = newSheet.getRange('B2:D33');
var values = range.getValues();
msg = JSON.stringify(values);
} else if (action == "deleteSheet") {
sheetName = e.parameter.sheetName;
var sheetToDelete = ss.getSheetByName(sheetName);
ss.deleteSheet(sheetToDelete);
msg = "Sheet deleted";
}
return ContentService.createTextOutput(msg);
}
With hindsight, this may be an issue for you:
as I now see that you want to paste the user id on Sheet1 ? If so replace the variable newSheetName
with a text block containing Sheet1
.
Brilliant sir, exactly what i wanted! thanks for your valuable time.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.