我有一个更新某些资源或公司内部网的脚本,我不断收到此错误:“无法调用方法”setHtmlContent“为null。”任何人都可以指出为什么我收到此错误以及如何解决它的方向。感谢您的帮助,以下是代码:
var DOMAIN_NAME = 'website.com';
var SITE_NAME = 'intranet-site';
var DOC_FOLDERS = ['Intranet Docs/Admin Resources/Accounts Payable Resources',
'Intranet Docs/Admin Resources/Finance Resources',
'Intranet Docs/Admin Resources/HR Resources',
'Intranet Docs/Admin Resources/Payroll Resources',
'Intranet Docs/Admin Resources/SSP Resources',
'Intranet Docs/Admin Resources/Vehicle & Incident Resources',
'Intranet Docs/Directors Resources/Advisory Boards',
'Intranet Docs/Comm and PR Resources/Logos and Graphics',
'Intranet Docs/Comm and PR Resources/Podcasts',
'Intranet Docs/Comm and PR Resources/Podcasts/Enrich Culture',
'Intranet Docs/Comm and PR Resources/Podcasts/Visionary Framework',
'Intranet Docs/Training and Program Resources/Base Camp',
'Intranet Docs/Training and Program Resources/Phone Greeting Training',
'Intranet Docs/Training and Program Resources/Safety Program'];
var WEB_PAGES = ['administration-resources/accounts-payable-resources',
'administration-resources/finance-forms',
'administration-resources/hr-forms-documents',
'administration-resources/payroll-resources',
'administration-resources/ssp-resources',
'administration-resources/vehicle-incident-resources',
'directors-resources/advisory-boards',
'communication-public-relation-tools/logos-and-graphics',
'communication-public-relation-tools/podcasts',
'communication-public-relation-tools/podcasts/enrich-culture',
'communication-public-relation-tools/podcasts/visionary-framework',
'training/base-camp',
'training/phone-greeting-training',
'training/safety-program'];
function updateAllIntranetResources() {
for (var idx=0; idx<WEB_PAGES.length; ++idx) {
var filesCnt = updateWebPage(WEB_PAGES[idx], DOC_FOLDERS[idx]);
}
return;
}
function updateWebPage(webpageName, folderPath) {
Logger.log('Folder: ' + folderPath);
var site = SitesApp.getSite(DOMAIN_NAME, SITE_NAME);
var webpage = site.getChildByName(webpageName);
var folder = DocsList.getFolder(folderPath);
var files = folder.getFiles();
// Begin building HTML for web page
var htmlContent = "<h3>Resource List</h3><hr>";
// Get file name and url of each file in folder and add to page
var filesCnt = files.length;
// Logger.log('Nbr of files: ' + filesCnt);
if (filesCnt > 0) {
var i = 0;
for (i = 0; i < filesCnt; i++) {
var file = files[i];
var fileUrl = file.getUrl();
var fileName = file.getName();
var htmlContent = htmlContent + '<a href="' + fileUrl + '" target="_blank">' + fileName + '</a><hr>';
// Logger.log('(' + i + ') fileUrl: ' + fileUrl);
// Logger.log('fileName = ' + fileName);
}
}
else {
htmlContent += "<b>(no resources found)</b>";
}
webpage.setHtmlContent(htmlContent);
return filesCnt;
}
答案 0 :(得分:0)
错误发生在
行中 webpage.setHtmlContent(htmlContent);
发生错误是因为webpage
为空。
它是出现在每个网页上还是只发生在少数网页上?另请注意,webpageName
必须是您在没有http://sites.google.com/a/domain_name.com/site_name/
如果您可以粘贴函数执行的日志或执行记录
,将会更有用