103 Apps Script Google Sheet Add Record
103 Apps Script: Google Sheet Add Record
Objective:
1. Parameter cmd for getting commands from clients.
2. Function taskManager() to handle app-specific commands.
3. Function addRecord() to perform add record operation.
3.1. Parameter SHT for sheet name.
3.2. Parameter tid, timestamp, name, gmail for new record.
3.3. Return record with rownum by calling getRecords by tid
1. Create Spreadsheet and Script.
Spreadsheet: 103appdatacrud.
Dummy Data:
A | B | C | D | |
1 | tid | timestamp | name | gmail |
2 | 123 | notarazi | notarazi@gmail.com | |
3 | 456 | notaraza | notaraza@gmail.com | |
4 | 789 | notarazu | notarazu@gmail.com | |
5 | ||||
6 | ||||
7 |
Script: 103appdatacrudscript.
2. Add codes.
/*script id*/ var SCPID=ScriptApp.getScriptId(); /*active spreadsheet */ var SST=SpreadsheetApp.getActiveSpreadsheet(); /*active spreadsheet id*/ var SSTID=SpreadsheetApp.getActiveSpreadsheet().getId(); /*OR if you are writing a standalone script*/ /*var SSTID=1FhDxI7j0PFtQYF0gCsiAQauQ1QZ-nDTWNPydpQPD3GE*/ /* web request listeners */ /* pass request to handleResponse */ function doGet(e) {return handleResponse(e);} function doPost(e) {return handleResponse(e);} /* handle action request */ function handleResponse(e) { var lock = LockService.getPublicLock(); lock.waitLock(30000); // wait 30 seconds before conceding defeat. try { var cmd = e.parameter.cmd; var output=[]; if (cmd == "app") { output = taskManager("app",e); }else if (cmd == "getadmins") { output = taskManager("getadmins",e); }else if (cmd == "addadmin") { output = taskManager("addadmin",e); } return ContentService.createTextOutput(JSON.stringify({"result": "success","data": output})).setMimeType(ContentService.MimeType.JSON); //return output } catch (e) {/*if error return this*/return ContentService.createTextOutput(JSON.stringify({"result": "error","error": e})).setMimeType(ContentService.MimeType.JSON);} finally { /*release lock*/ lock.releaseLock();} } /*taskManager*/ function taskManager(cmd,e){ link download
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.