Showing All Versions of “Append Changes to Existing Text” in a Data View Web Part (DVWP)
While flying across the country to SPTechCon SFO 2011, I was going through some of my old “blog posts I should do sometime” lists and came across this cool trick. Brendan Horner (@hornerit) shared it with me months ago via Twitter and I socked it away for one of those extra moments. Well, I found that moment. It’s not something which hasn’t been written about before, but it’s something I’m asked about from time to time, and I never remember how to do it, so here you go.
You’ve probably used the “Append Changes to Existing Text” trick in a list at least once. If not, here’s how it works. You have to have versioningĀ turned on for the list for this to work. Then if you create a Multiple lines of text column, at the bottom of the settings you’ll see the option.
Setting the option to “Yes” lets you keep a sort of running log in that column. I’ve used it many times in tasks lists so that each person can add their $.02 during the process.Ā Here’s what it might look like (with some silly test data):
One problem with this cool functionality is that in views, you don’t get to see the strings of text, just a link that takes you to the DispForm for the item. It’s a cumbersome UI choice, for sure.
So naturally, we’d like to be able to turn to a Data View Web Part (DVWP) to improve the user experience. To make this work, you need to add the following line into your XSL:
<SharePoint:AppendOnlyHistory FieldName="Comments" runat="server" ControlMode="Display" ItemId="{@ID}"/>
When you do this, you get a nice listing of the history, like this:
Much nicer! Thanks, Brendan.
Hi,
In MOSS 2007 this wasn’t giving problem at all, but in SharePoint 2010 it is eating my head, ok the new line is almost solved my problem but i want to show only the last history not all of them, please help
If you only want to show the last version, then you may want to look at the Versions Web Service (I’m guessing).
M.
The correct code for sharepoint 2010 could be the below.
this works for me at least…
Jay:
Your code didn’t make it through, unfortunately.
M.
<SharePoint:AppendOnlyHistory FieldName="Comments" runat="server" ControlMode="Display" ItemId="{$thisNode/@ID}"/>
Basically @ID was replaced with $thisNode/@ID
Hi. I’ve been looking for a way to achieve this without using Sharepoint Designer which I don’t have access to. Does anyone know of another way to achieve this?
Paul:
I can’t think of an easy way. You could write script using SPServices to look into the versions. It’s doable, but probably more work. In fact, it might make a nice function for SPServices!
M.
Hi
I want to export all my view entries to excel sheet
At present when I Export the list to Spreadsheet I only get the last comment.
How can i export with all comments. Is this possible?
Thanks in Advance
Kiran:
Since “Append changes to existing text” uses versionng as the underlying mechanism, no there’s nothing available out of the box. As you’ve realized, only the current version is downloaded.
M.
Hi this worked for me. The only issue I have is it puts the name and date on one line and then puts the comment on the line below instead of on the same line as in your example. Any ideas how I can get the comments and name and date to all appear on the same line?
Thanks
I’ve actually worked this out. I was using a custom comments column instead I’m using the existing site column Append only comments and that displays as I wanted.
This is really helpful!
However, is there a way to display only the latest entry/version?
Did you try just showing the column value in the DVWP?
M.
The organization I support is still using SP 2007. I have tried referencing the code you supplied and use it via SP Designer 2007 on SP 2007 site and it does not appear to work. Will this work in a SP 2007 environment? Thank you
Jerry:
When I posted this, I was working with 2007, so yes it should work.
M.
Marc
Thank you for your response. I am not sure where in the sequence to add the entry you provided and I’m not sure if you can provide any particular guidance without more specifics from me but is there a specific location I should place this entry?
Thanks Marc,
Jerry
Jerry:
Yes, it’s a little hard to be sure what to tell you, but you add the line
where you are currently displaying the column value in the DVWP. It’ll look something like this by default:
M.
Marc
Cannot thank you enough; I was able to get the comments to display. I have some other issues now but will deal with those one step at a time.
Thank you again,
Jerry