1

これが私が解決しようとしてきたシナリオです。ユーザーがサイトにアクセスしてファイルをアップロードすると、そのファイルが Google ドキュメント コレクションに送信され、そのドキュメントへのリンクが生成され、管理者に電子メールで送信されます。アナウンスにドキュメントへのリンクを含めるために、このスクリプトを介して自動的に更新したいアナウンス ページがあります...コードは次のとおりです。

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 = "me@example.com";
    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;
}

誰か"docUrl"が発表に参加するのを手伝ってくれませんか? ありがとうございました。

関数はnewAnnouncement(parameter)無視できます。それが私を助けるのに役立つかもしれない場合に備えてあります:)

4

1 に答える 1

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>');

新しいアナウンスごとに、アナウンスに新しいタイトルを付けてください。たとえば、「これはタイトルです」を複数回使用することはできません。これらの変更を行ってもまだ機能しない場合は、この行を try/catch ブロックでラップし、例外をログに記録して、何が問題なのかを確認してください。

try {
  site.createAnnouncement("this is a title", '<a href="' + docUrl + '">LINK TEXT</a>');
} catch (err) {
  Logger.log(err);
}
于 2011-08-26T15:09:18.343 に答える