2017-01-23 30 views
0

ここにコードがあります。回答者がフォームを提出したときにトリガーを使用するので、私はデバッグできません。Googleアプリスクリプトでドキュメントを保存するにはどうすればよいですか?

// This code opens the doc and names it what you wanted it named above. It also appends any other language to the title that you wish. My sample below will title each document as docName + 'for' + Lname or (OA Graduate Assistant Application for Last Name of user). 
    var copyId = DriveApp.getFileById(docTemplate) 
    .makeCopy(docName+' for '+ Lname) 
    .getId(); 

    // Open the temporary document 
    var copyDoc = DocumentApp.openById(copyId); 

    // Get the document’s body section 
    var copyBody = copyDoc.getActiveSection(); 

    //code that makes edits 
    copyBody.replaceText('keyTimestamp', Timestamp); 
    copyBody.replaceText('keyPemail', Pemail); 

//define the source folder to save the file in 
    var dir = DriveApp.getFolderById(folderid); 

//add this file to the source folder 
    dir.addFile(copyDoc); 


    copyDoc.saveAndClose(); 

指定したフォルダとGoogleドライブ全体にファイルが保存されていません。どうしたの?すべての変数が正しく定義されています(私はvarステートメントを省略しました)。

+0

有効なドライブファイルIDである[getFileById(id)](https://developers.google.com/apps-script/reference/drive/drive-app#getfilebyidid)に値が渡されていますか? – noogui

+0

はいファイルが有効です – NoMoreErrors

+0

この問題をデバッグする方法はありますか? – NoMoreErrors

答えて

0

次のスクリプトはどうですか?

"addFile()"はDriveAppクラスのメソッドです。そのため、DriveAppの方法でファイルを取得する必要があります。あなたのスクリプトでは、 "getFileById()"を使用しました。

// This code opens the doc and names it what you wanted it named above. It also appends any other language to the title that you wish. My sample below will title each document as docName + 'for' + Lname or (OA Graduate Assistant Application for Last Name of user). 
var copyId = DriveApp.getFileById(docTemplate) 
.makeCopy(docName+' for '+ Lname) 
.getId(); 

// Open the temporary document 
var copyDoc = DocumentApp.openById(copyId); 

// Get the document’s body section 
var copyBody = copyDoc.getActiveSection(); 

//code that makes edits 
copyBody.replaceText('keyTimestamp', Timestamp); 
copyBody.replaceText('keyPemail', Pemail); 

//define the source folder to save the file in 
var dir = DriveApp.getFolderById(folderid); 

//add this file to the source folder 
dir.addFile(DriveApp.getFileById(copyId)); 


copyDoc.saveAndClose(); 

解決策がない場合は、お詫び申し上げます。

+0

が表示されます。ご迷惑をおかけして申し訳ありません。 – NoMoreErrors

+0

エラーについて質問できますか? – Tanaike

関連する問題