简体   繁体   中英

After creating a new sites List Page How can I add values to it?

I have created a new List Page but don't know how to populate it with values. As newDomainpage doesn't contain any values yet, I keep getting a NULL error while trying to set the value.

var domainPage = SitesApp.getPageByUrl("https://sites.google.com/a/idearebel.com/url-of-page");
var newDomainPage = newClientPage.createListPage(projectName, projectUrl, domainPageContent, [ "Used", "Title", "Notes" ]);

var domainPageItems = domainPage.getListItems();
var newDomainPageitems = newDomainPage.getListItems();

for(var i in domainPageItems) {
    newDomainPageitems[i].setValueByIndex(2, domainPageItems[i].getValueByName("Title"));
    // Logger.log(domainPageItems[i].getValueByName("Title"));
}

I am new to Google Scripts, therefore any help will be much appreciated.

Resolved, I was using the wrong function for the job. addListItem is the correct function to use.

for(var i in domainPageItems) {
    newDomainPage.addListItem([ "", domainPageItems[i].getValueByName("Title"), "", "" ]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM