Class ListItem

ListItem

A Sites ListItem - a list element from a Sites List page.

Methods

MethodReturn typeBrief description
deleteListItem()voidDeletes this list item.
getDatePublished()DateReturn the date this list item was first published.
getLastUpdated()DateReturn the date this comment was last updated.
getParent()PageGet the parent page of this list item.
getValueByIndex(index)StringGet the value of this ListItem for a numbered column.
getValueByName(name)StringGet the value of this ListItem for a named column.
setParent(parent)ListItemSet the parent page of this list item.
setValueByIndex(index, value)ListItemSet the value of this ListItem for a numbered column.
setValueByName(name, value)ListItemSet the value of this ListItem for a numbered column.

Detailed documentation

deleteListItem()

Deletes this list item.

// This code sample deletes all list items from a List page
// Running this code sample against a Page that is a standard web page will
// cause getListItems() to throw an exception
var page = SitesApp.getSite('demositeappsscript').getChildByName('mylistpage');
var items = page.getListItems();
for(var i = 0; i < items.length; i++) {
  items[i].deleteListItem();
}

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getDatePublished()

Return the date this list item was first published.

var page = SitesApp.getSite('example.com', 'mysite').getChildByName('mylistpage');
var items = page.getListItems();
var date = items[0].getDatePublished();

Return

Date — the date of original publication

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getLastUpdated()

Return the date this comment was last updated.

var page = SitesApp.getSite('example.com', 'mysite').getChildByName('mylistpage');
var items = page.getListItems();
var date = items[0].getLastUpdated();

Return

Date — the last updated date

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getParent()

Get the parent page of this list item.

var page = SitesApp.getSite('example.com', 'mysite').getChildByName('mylistpage');
var items = page.getListItems();
// parentPage will equal page
var parentPage = items[0].getParent();

Return

Page — the parent page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getValueByIndex(index)

Get the value of this ListItem for a numbered column.

var page = SitesApp.getSite("demositeappsscript").getChildByName("mylistpage");
var listItem = page.getListItems()[0];

// Remember that rows are 0 indexed. This returns the item in the first column
// of the list. If an index that is greater than the number of columns is used,
// the script will throw an "InvalidArgument: index" exception.
var value = listItem.getValueByIndex(5);

Parameters

NameTypeDescription
indexIntegerthe column to get the value of

Return

String — the value of that column

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getValueByName(name)

Get the value of this ListItem for a named column.

var page = SitesApp.getSite("demositeappsscript").getChildByName("mylistpage");
var listItem = page.getListItems()[0];

// Suppose we have a column named "Owner" - this will let us fetch the value
// for the list item
var value = listItem.getValueByName("Owner");
Logger.log(value);

Parameters

NameTypeDescription
nameStringthe column to get the value of

Return

String — the value of that column

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setParent(parent)

Set the parent page of this list item.

var page = SitesApp.getSite('example.com', 'mysite').getChildByName('mylistpage');
var secondListPage = SitesApp.getSite('example.com', 'mysite')
                             .getChildByName('secondlistpage');
var items = page.getListItems();

// Returns secondListPage
var parentPage = items[0].setParent(secondListPage).getParent();

Parameters

NameTypeDescription
parentPagethe new parent

Return

ListItem — this ListItem for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setValueByIndex(index, value)

Set the value of this ListItem for a numbered column. For URL columns the value must be an XHTML anchor tag, with XML entities escaped.

var page = SitesApp.getSite("example.com", "mysite").getChildByName("mylistpage");
var listItem = page.getListItems()[0];
listItem.setValueByIndex(1, 'This is the new value');
listItem.setValueByIndex(2, '<a href="http://www.example.com?a=1&amp;b=2">Example</a>');

Parameters

NameTypeDescription
indexIntegerthe column to set the value of
valueStringthe new value

Return

ListItem — this ListItem for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setValueByName(name, value)

Set the value of this ListItem for a numbered column. For URL columns the value must be an XHTML anchor tag, with XML entities escaped.

var page = SitesApp.getSite("demositeappsscript").getChildByName("mylistpage");
var listItem = page.getListItems()[0];
listItem.setValueByName('Owner', 'Eric');
listItem.setValueByName('Page', '<a href="http://www.example.com?a=1&amp;b=2">Example</a>');

Parameters

NameTypeDescription
nameStringthe column to set the value of
valueStringthe new value

Return

ListItem — this ListItem for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds