【问题标题】:Google Apps Script - Document and AnnouncementsGoogle Apps 脚本 - 文档和公告
【发布时间】:2011-07-13 18:46:10
【问题描述】:

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

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) 函数可以忽略不计,以防万一它可以帮助你:)

【问题讨论】:

    标签: google-apps google-apps-script google-sites


    【解决方案1】:

    如果你改变这一行,你应该能够让它工作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多