1

所以这是我一直试图解决的场景。一个用户来到我们的网站,上传一个文件,该文件被发送到一个谷歌文档集合并生成一个指向该文档的链接,该链接通过电子邮件发送给管理员。我有一个公告页面,我想通过此脚本自动更新,以在公告中包含指向文档的链接......这是代码

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 回答