5

In the Flat.aspx page of a discussion forum, I have to highlight the reply if the poster belongs to a certain group. How do I achieve that?

I tried modifying the Profile.xsl file that the list view uses, but none of the changes are getting reflected. Am I looking at the wrong xsl file? Or is there some other way to do it?

3

This could be accomplished on client side. Below is provided full solution description.

Script for highlighting discussion list replies:

ExecuteOrDelayUntilScriptLoaded(highlightDiscussion, "sp.js");



function highlightDiscussion()
{
   var discussionGroupId = 3;
   var clientContext = new SP.ClientContext.get_current;
   var groups = clientContext.get_web().get_siteGroups();
   var group = groups.getById(discussionGroupId);   //
   this.groupUsers = group.get_users();
   clientContext.load(groupUsers);
   clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}


function resolveUserForReply(replyItem)
{
     var userEntry = {};
     var replyRow = replyItem.closest('tr');
     var userUrl = replyRow.find('a').attr('href');
     userEntry.ID = userUrl.match(/ID=([^&]+)/)[1];
     return userEntry;
}


function highlightReply(replyItem)
{
    replyItem.css({'background-color': '#00ffcc'});
}

function highlightReplyForUser(userId)
{
    $('div[class^="ExternalClass"]').each(function(index) {
        var user = resolveUserForReply($(this));
        if(userId == user.ID)
           highlightReply($(this)); 
    });
}


function onQuerySucceeded() {
    var ie = groupUsers.getEnumerator();
    while (ie.moveNext()) {
       var user = ie.get_current();
       highlightReplyForUser(user.get_id());
    }
}

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

How to make it work:

  1. Save this script as a file DiscussionsHighlight.js and place it to LAYOUTS folder
  2. Embed specified file and jquery files into discussion list, for example add it to Flat.aspx like shown below:

enter image description here

Results

On picture below is displayed discussion list with highlighted replies for users who belongs to specific group (see parameter discussionGroupId in script )

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.