2011-07-13 27 views
1

これは私が解決しようとしているシナリオです。ユーザーがGoogleサイトにアクセスしてファイルをアップロードすると、そのファイルはGoogleドキュメントコレクションに送信され、そのドキュメントへのリンクが生成され、管理者に電子メールで送信されます。私は誰かが発表に"docUrl"を得ることで私を助けてもらえ、私が発表にドキュメントへのリンクを含めるには、このスクリプトを経由して自動的に更新したいと思い告知ページ...ここにコードGoogle Appsスクリプト - ドキュメントとお知らせ

function newAnnouncement(parameter){ 
    var site = SitesApp.getPageByUrl("https://sites.google.com/a/westcongps.com/dhcorpintranettestsite/company-blog"); 
    site.createAnnouncement("this is the title", '<a href="' + parameter + '">LINK TEXT</a>'); 
} 

function doGet(e) { 
    // creates the ui application 
    var app = UiApp.createApplication(); 
    // set's up the application user interface. 
    var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data'); 
    var formContent = app.createVerticalPanel(); 
    form.add(formContent); 
    var fileUp = app.createFileUpload().setName('thefile'); 
    var submit = app.createSubmitButton('Submit'); 
    formContent.add(fileUp); 
    formContent.add(submit); 
    app.add(form); 
    submit.setPixelSize(75, 20); 

    return app; 
} 

function doPost(e) { 
    // data returned is a blob for FileUpload widget 
    var fileBlob = e.parameter.thefile; 
    var doc = DocsList.createFile(fileBlob); 
    //var to store the folder the file will be uploaded to 
    var folder = DocsList.getFolder("collection"); 
    //adds the document to the folder ^^^ 
    doc.addToFolder(folder); 
    var emailAddress = "[email protected]"; 
    var subject = "subject"; 
    var body = "A new quote has been requested, please process the attachment"; 
    // send a notification email with attached file or link to uploaded file 
    //gets the URL of the uploaded document 
    var docUrl = doc.getUrl(); 
    //adds the body text to the doc url to create the body message 
    var bodyUrl = body + "\n" + docUrl; 
    // gets the page I would like to post the announcement on 
    var site = SitesApp.getPageByUrl("http://example.com/announcements-page"); 
    site.createAnnouncement("this is the title", '<a href="linkToGoogleDoc">LINK TEXT</a>'); 
    MailApp.sendEmail(emailAddress, subject, bodyUrl); 
    app.close(); 
    return app; 
} 

がありますか?ありがとうございました。

newAnnouncement(parameter)機能は、それはそれはあなたが私を助けることに役立つかもしれない場合があります:)

答えて

0

あなたは、この行を変更する場合は、この作業を取得することができるはず、無視することができます。

site.createAnnouncement("this is the title", '<a href="linkToGoogleDoc">LINK TEXT</a>'); 

にこれは:

site.createAnnouncement("this is a title", '<a href="' + docUrl + '">LINK TEXT</a>'); 

新しい発表ごとに、アナウンスに新しいタイトルを付けるようにしてください。たとえば、「this is a title」を複数回使用することはできません。これらの変更を行ってもまだ動作していない場合は、この行をtry/catchブロックにラップし、例外が発生して何がうまくいかないかを確認してください。

try { 
    site.createAnnouncement("this is a title", '<a href="' + docUrl + '">LINK TEXT</a>'); 
} catch (err) { 
    Logger.log(err); 
} 
関連する問題