0

我有一个脚本可以更新公司 Intranet 上的某些资源,但我不断收到此错误:“无法调用 null 的方法“setHtmlContent”。” 谁能指出我为什么会收到此错误以及如何解决它的方向。感谢您的帮助,这里是代码:

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

1 回答 1

0

错误发生在该行

 webpage.setHtmlContent(htmlContent);

发生错误是因为webpage为空。它发生在每个网页上还是只发生在少数几个网页上?另外,请注意,webpageName必须是您在浏览器的 URL 中看到的,没有http://sites.google.com/a/domain_name.com/site_name/

如果您可以粘贴函数执行的日志或执行记录,这将更加有用

于 2013-08-26T14:21:03.827 回答