Comments In UGC

Agility User Generated Content has been extended to support commenting as a built in feature. Comments can be enabled on a content definition, or UGC Record Type. When Comments are enabled a new UGC Comment Record Type will be created to store the comment content items.

Comment content items use the same API calls as standard UGC records for saving (SaveRecord) and retrieving records (GetRecord/SearchRecords). An additional helper method has been added to help search for comments as well and produce comment hierarchies when comments are expected to be threaded. This new call is "SearchComments" and you can see the method signature below.

Base Comments Object

Below is the base Comment Object Structure

var comment = {
   ID: -1,
   RecordTypeName: "CommentsForBlogEntries",
   RelatedContentID: 123,
   Name: "MyName",
   Comment: "My Comment",
   ParentRecordID: -1
};

CommentSearchArg Object Properties API.CommentSearchArg = function() {
   RelatedContentID: -1;
   PageSize: 20;
   RecordOffset: 0;
   SortedField: "CreatedOn";
   SortDirection: "DESC";
   RecordTypeName: "";
   CacheKey = null;
   OtherStates = [];
   State = API.RecordState.Published;
   FileStorage = API.FileStorage.RelativeURL;
   Columns = [];
}
Agility.UGC.API.SearchComments(commentSearchArg, callback)
The SearchComments API call will return a list of comments based on the search criteria. The call is very similar to the SearchRecords call and the CommentSearchArg object share many of the same properties. The Primary property that must be set it the RelatedContentID property which is the link between the comments and the item being commented on.
var commentSearchArg = {
    RelatedContentID: 1234, //ID you are pulling comments for
    PageSize: 10,
    RecordOffset: 0,
    SortedField: "CreatedOn",
    SortDirection: "asc",
    RecordTypeName: "CommentRecordTypeName"
 };

Agility.UGC.API.SearchComments(commentSearchArg, function (data) {
    if (data.ResponseType == 0) {
        //Render Comment Data
        //data.ResponseData.Records
        //data.ResponseData.TotalRecords
    }
});
		
                        
Agility.UGC.API.SaveRecord(comment, callback)
Saving a comment is done by performing the same SaveRecord call as you would with any UGC item. The comment record must be in a specific format though as you can see from the code example below
var comment = {
    ID: -1,
    RecordTypeName: "CommentsForBlogEntries", //record type/content reference name
    RelatedContentID: 123, // content item to link to
    ParentRecordID: null, //for nested comments

    //Default Comment Fields
    Name: "My Name", 
    Comment: "This is my comment
};

Agility.UGC.API.SaveRecord(comment, function (data) {
    alert("Comment Submitted Successfully");
});
                        

LOGIN

Log in with your Agility username and password or
register for the site




Log In

REGISTER












Register

FORGOT PASSWORD