Displaying Tags & Notes on Items in SharePoint 2010

This post is a continuation of an article written by Glyn over on his blog. You can read the full article here: Showing which list items have tags or notes in SharePoint 2010.

What I’ll be covering in this post, is extending his article to solve the issues he mentions in his Next Steps and Limitations bit:

I’m fairly happy with the result that this script and technique gives, although there are some nagging annoyances. Whilst investigating this I tried to repeat the same behaviour as the Tags And Notes icon found in the ribbon, i.e. it would be nice to be able to click on the icons and view/ add tags and notes for the individual items. Unfortunately I found that by adding in the functions to open up the dialog with multiple instances on a page it would always refer to the first item clicked.

So to begin, let’s review his process:

  1. Let’s assume you have a document library called Shared Documents.
  2. Within the Shared Documents document library, create a new column named Tags And Notes. In this case, both Glyn and myself used Single Line of Text.
  3. On the home page of your team site, you’ll want to add the Shared Documents web part to the page, and within the web part properties, modify the view so that the Tags And Notes column is visible.

  4. Upload the script that Glyn put together into a suitable location. In my case, I uploaded it into the Site Assets library as he recommends. You’ll want to name the file jquerysocialdata.js. I’ve made modifications to this file, that I’ll discuss shortly, so you can grab an updated version of this file from here.
  5. Reference the script in a Content Editor Web Part (CEWP) added to the same page that the Shared Documents web part has been added to.
  6. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="/SiteAssets/jquerysocialdata.js"></script>

Now let’s talk about the changes I made to get this to work. I want to mention that I ran into the exact same issue as Glyn initially. The logic I had added to popup the Tags and Notes in a modal would only ever display the data for the first item I happened to click on. If I refreshed the page, and clicked on a different item, that item would load correctly. Any subsequent items I clicked on, would always load the data from the first item clicked. So some sort of caching going on.

Initially, the logic I was trying to emulate was leveraging the TagDialogOpener.Open call, which is exactly the same call that’s used by the Tags & Notes icon in the Ribbon.

SafeRunFunction(function() { TagDialogOpener.Open(strUrl, title, '0'); }, 'SocialData.js', 'TagDialogOpener');

However, nothing I did would result in it loading the correct data after the second click. I spent a lot of time breaking down and looking into how this call was made, even going so far as reviewing the SocialData.js file that it’s ultimately pulling from, and while my understand of it all was a lot better, it didn’t result in a solution.

So I went about it a different way. I decided to leverage the SPModal class and make the call myself. Below are the changes I had to make to the jquerysocialdata.js file to make this work. Please note you don’t have to make any of these changes, I’ve done it for you already.

  1. First thing I did was in the OutputTagsAndNotesImage method, I added an onclick event to the ms-mini-socialNotif a tag. This call required two parameters: strUrl and title. Since neither of these two were being passed into this function, I modified the FindTagsAndNotes function so that they were sent through.
  2. I then added a new function SendTag that basically wired up the link to open a modal dialog when the image was clicked.
    function SendTag(strUrl, title) {
    	// remove first '/'
    	title = title.substring(1);
    	// replace '/' with ' - '
    	title = title.replace('/', ' - ');
    	var f={url:location.protocol + '//' + location.hostname + "/_layouts/socialdataframe.aspx?Url="+strUrl+"&mode=0",args:null,title:title,width:600,height:470};
    	SP.UI.ModalDialog.showModalDialog(f);
    }
  3. One thing to note, is that the mode parameter determines whether the modal opens the Tags tab by default or the Note Board tab by default. By tweaking this parameter, so 1 for Note Board and 0 for Tags, you can modify it’s default behaviour.

    How cool is that? Give it a try and let me know if you run into any issues!

4 Responses to “Displaying Tags & Notes on Items in SharePoint 2010”

  1. Jakob Nøtseth December 12, 2012 at 1:50 am #

    Hi, add title to the url-querystring to avoid caching issues

    var f={url:location.protocol + ‘//’ + location.hostname + “/_layouts/socialdataframe.aspx?Url=”+strUrl+”&mode=” + mode + “&Title=” + title,args:null,title:title,width:600,height:470};

  2. shereen December 24, 2012 at 12:40 pm #

    Interesting Jakob, were you having caching issues with the code above that were resolved by adding Title?

  3. Duncan April 2, 2013 at 4:42 am #

    Hi Shereen, I can’t get this to work – I’m trying to add it to an announcement for internal communications – our comms department would like to know what staff think of the posts they make? Any ideas?

  4. shereen April 7, 2013 at 6:08 pm #

    Hi Duncan,

    What have you tried? Or do you have any errors you can give me that might help us troubleshoot together?

Leave a Reply