Overwrite file. Overwrite Script applications.
It is not a question of creating a new Script application. This will not help me. I need to update an existing Script application file. This question is similar to creating a new file, but this is not the same problem. The syntax of the update, and the requirements for updating can be quite different from creating a new file, and I can not get a solution from the answer to create a new file. I looked at the answer to creating a new file and did not answer my question.
I tried to use the Advanced Drive Service to upgrade an existing Script application with another Apps Script file.
function updateMyScript() {
var targetFileID = 'File ID';
var dataSource = {
"files": [
{
"id":"739a57da-f77c-4e1a-96df-7d86ef227d62",
"name":"Code",
"type":"server_js",
"source":"function doGet() {\n return HtmlService.createHtmlOutputFromFile(\u0027index\u0027);\n}\n"
},
{
"id":"2c7e8b5a-dbc5-4cd2-80e9-77b6291b3167",
"name":"index",
"type":"html",
"source":"\u003chtml\u003e\n \u003cbody\u003e\n New message!!\n \u003c/body\u003e\n\u003c/html\u003e"
}
]
};
var filesResource = Drive.Files.get(targetFileID);
var blob = Utilities.newBlob(JSON.stringify(dataSource), "application/vnd.google-apps.script+json");
var whatRezult = Drive.Files.update(filesResource, targetFileID, blob, {"convert":"true"});
Logger.log('whatRezult: ' + whatRezult);
};
id dataSource .gs html . , "target" Apps Script JSON, JSON . , , . . Script , "sub" . . name type . , , , server_js "html". , source Script . , , , .
target ID .
Advanced Drive UrlFetchApp.fetch(), . Script. , , - , Script.
:
Drive.Files.update(filesResource, targetFileID, blob, {"convert":"true"});
:
.
, , - . , .