Google Apps 脚本 - 文档和公告

发布于 2024-11-23 15:24:58 字数 2296 浏览 0 评论 0原文

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

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

有人可以帮助我将 "docUrl" 放入公告?谢谢。

newAnnouncement(parameter) 函数可以被忽略,它就在那里,以防它可以帮助你帮助我:)

So here's the scenario I've been trying to solve. A user comes to our site, uploads a file, that file is sent to a google docs collection and generates a link to that doc which is emailed to an administrator. I have an announcements page that I would like to update automatically via this script to include the link to the doc in the announcement... here's the code

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

Could someone help me with getting the "docUrl" into the announcement? Thank you.

the newAnnouncement(parameter) function can be ignored, it's there in case it might help you help me :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦等七年七年为一梦 2024-11-30 15:24:58

您应该能够使其正常工作

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

You should be able to get this to work if you change this line:

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

to this:

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

Make sure that for each new announcement, you give the announcement a new title. For example, you can't use "this is a title" more than once. If you make these changes, and it still isn't working, try wrapping this line in a try/catch block and logging the exception to see what is going wrong.

try {
  site.createAnnouncement("this is a title", '<a href="' + docUrl + '">LINK TEXT</a>');
} catch (err) {
  Logger.log(err);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文