Google Apps Script

Class Comment

A Comment attached to any Sites page.

Methods

MethodReturn typeBrief description
deleteComment()voidDeletes this comment.
getAuthorEmail()StringGets the email address of the author of this comment.
getAuthorName()StringGets the name of the author of this comment.
getContent()StringReturn the content of this comment as a String.
getDatePublished()DateReturn the date this comment was originally published.
getLastUpdated()DateReturn the date this comment was last updated.
getParent()PageGet the parent page of this comment.
setContent(content)CommentSet the content of this comment.
setParent(parent)CommentSet the parent page of this comment.

Detailed documentation

deleteComment()

Deletes this comment.

 
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
 var comments = pages[0].getComments();

 // Let's delete all of Eric's comments
 for(var i = 0; i < comments.length; i++) {
   if(comments[i].getAuthorEmail() == "eric@example.com") {
     comments[i].deleteComment();
   }
 }
 

getAuthorEmail()

Gets the email address of the author of this comment.

Return

String — the author's email


getAuthorName()

Gets the name of the author of this comment.

 
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
 var comments = pages[0].getComments();
 var comment = comments[0];
 var authorEmail = comment.getAuthorEmail();
 

Return

String — the author's name


getContent()

Return the content of this comment as a String.

 
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
 var comments = pages[0].getComments();
 var content = comments[0].getContent()
 

Return

String — the comment content


getDatePublished()

Return the date this comment was originally published.

 
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
 var comments = pages[0].getComments();
 var date = comments[0].getDatePublished();
 

Return

Date — the date of original publication


getLastUpdated()

Return the date this comment was last updated.

 
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
 var comments = pages[0].getComments();
 var date = comments[0].getLastUpdated();
 

Return

Date — the last updated date


getParent()

Get the parent page of this comment.

 
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
 var comments = pages[0].getComments();
 var comment = comments[0];

 // parentPage should be the same page as pages[0]
 var parentPage = comment.getParent();
 

Return

Page — the parent page


setContent(content)

Set the content of this comment.

 
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
 var comments = pages[0].getComments();
 var comment = comments[0];
  comment.setContent("New Content");

 // Note that this returns a Comment, so you can chain the method calls
 var updatedContent = comment.setContent("New Content")
                             .getContent();
 

Parameters

NameTypeDescription
contentStringthe new content

Return

Comment — this Comment for chaining


setParent(parent)

Set the parent page of this comment.

 
var pages = SitesApp.getSite('example.com', 'mysite').getChildren();
 var comments = pages[0].getComments();
 var comment = comments[0];

 // Let's say we want to move the comment to its parent's next neighbor ..
 // This will only work if the example site has multiple children
 var newParentPage = comment.setParent(pages[1]).getParent();
 

Parameters

NameTypeDescription
parentPagethe new parent

Return

Comment — this Comment for chaining

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.