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;
}
有人可以帮助我将 "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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够使其正常工作
如果您将此行更改为:
确保对于每个新公告,您都为该公告指定一个新标题, 。例如,您不能多次使用“这是标题”。如果您进行了这些更改,但它仍然不起作用,请尝试将此行包装在 try/catch 块中并记录异常以查看出了什么问题。
You should be able to get this to work if you change this line:
to this:
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.