所以这是我一直试图解决的情景。用户访问我们的网站,上传文件,该文件被发送到谷歌文档集合,并生成该文档的链接,该文档通过电子邮件发送给管理员。我有一个公告页面,我想通过这个脚本自动更新,以包含公告中文档的链接...这里是代码
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)
函数,它可以帮助我帮助我:)
答案 0 :(得分: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);
}