1,804 articles and 14,828 comments as of Wednesday, May 11th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Wednesday, October 21, 2009

Taming the Elusive “Calculated Column” – Referencing a Multiple Lines of Text Column With Append Text: Part 1

As a follow-up to a previous article I wrote on “Referencing Multiple Lines of Text” in a calculated column, and to address an issue brought up on the STP forums regarding how to use this technique with a “Multiple lines of Text” column that is set to “Append Changes to Existing Text” and how to view all of the versions (appended changes) in a regular list, I give you the following:

“How to reference a ‘Multiple Lines of Text’ column in a ‘Calculated Column’ to display a complete list of appended changes to all items on a list as a group – in 10 Easy Steps”.

Using the exact same technique I walked through in the previous article, we’ll create a custom list, add in a temporary column to set our calculated column reference, delete the column and recreate it as the appropriate type, then use some JavaScript to tie it all together with a custom view.

Step 1: Create your list

For this, I’ll just be using a custom list called “All Comments”. 

In order for the “Append” part to work, we need to turn on “Versioning” in the list settings (Settings > List Settings > Versioning Settings > Choose “Create a version each time you edit an item in this list”).

Step 2: Create your temporary column

In order for you to be able to reference a “Multiple Lines of Text” column from a “Calculated Column”, you must fool the system into thinking its ok to do so. 

The technique is simply to create a column with the name you intend to use in your formula making sure to leave all of its settings as default (leave it as a “Single Line of Text” type).

Create a new column called “Commentsleaving its setting as default.

Append Text

Step 3: Add the Calculated Column

Since we now have our temporary column created, we can make a reference to it in our “Calculated Column” without any errors.

Create a new column called “Expanded Comments”, make it a “Calculated” type and add in the following formula:

=[Comments]

Append Text

Step 4: Reset our Temporary column

Once we’ve made our reference, we can go back into the “Comments” column, delete it, and then recreate it as the type we really want to use.

Delete the “Comments” column then immediately recreate it (making sure that you are using the exact same name for the column), and this time set it as a “Multiple Lines of Text” type and choose the option to “Append Changes to Existing Text”.

Append Text

Step 5: Test Round 1

To test this and make sure everything is working at this point, create a new item on the list and you should see something similar to this:

Append Text

Step 6: The HTML Calculated Column

Notice that our calculated column, although displaying the correct information, is rather ugly at the moment with the added “div” tags surrounding the comment text? 

To fix this, we’ll once again tap into Christophe’s “TextToHTML” script and add it in to a CEWP on the page.

On the view page, add in a CEWP and paste in the following script into its “Source Editor”:

  /*>
  Text to HTML - version 2.1<br>
  Questions and comments: [email protected]
  */
  function TextToHTML(NodeSet,  HTMLregexp) {
  var CellContent = "";
  var i=0;
  while (i < NodeSet.length){
  try {
  CellContent = NodeSet[i].innerText || NodeSet[i].textContent;
  if (HTMLregexp.test(CellContent)) {NodeSet[i].innerHTML = CellContent;}
  }
  catch(err){}
  i=i+1;
  }
  }
  // List views
  var regexpTD = new  RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
  TextToHTML(document.getElementsByTagName("TD"),regexpTD);
  </script>

Note – although I have intentionally trimmed out some of the unused lines of script for this specific walkthrough, you can copy the entire script from Christophe’s site and use it as is – http://www.pathtosharepoint.com/HTMLcc

Immediately you should now see the comments being displayed appropriately:

Append Text

Next, we need to add in a few edits to the item on the list in order to see how the system handles these “versions” of the text.

Edit the item and add in a few changes (saving after each one). 

By default, the list itself will only display the most recent edit (standard behavior of “Versioning”), but for reference sake, click on the item to view its details then click on the “Version History” link to see all of our changes.

Append Text

Append Text

Although we “could” use this page as our method of seeing all of the comments, it’s not practical since it only lists out the versions for an individual item, not for a group of items.

Till next time…
– Dessie

Tomorrow Dessie will show us the "Magic" URL.

Dessie LunsfordDessie Lunsford
Points-of-Sharing 

View all entries in this series: Dessie Lunsford-Logic Formulas»
Entries in this series:
  1. Taming the Elusive "Calculated Column"
  2. EndUserSharePoint.com: Taming the Elusive "Calculated Column" - Customizing a Task List
  3. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Task List (Part II)
  4. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Task List (Part III)
  5. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Task List (Part IV)
  6. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Text and Data
  7. EndUserSharePoint.com: Taming the Elusive "Calculated Column" - Customizing a Contacts List (Part I)
  8. EndUserSharePoint.com: Taming the Elusive "Calculated Column" - Customizing a Contacts List (Part II-I)
  9. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Contacts List (Part II-II)
  10. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Contacts List (Part II-III)
  11. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part III)
  12. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part IV)
  13. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part V)
  14. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part VI)
  15. Taming the Elusive “Calculated Column” – Lookup and Reference
  16. Taming the Elusive “Calculated Column” - Logic
  17. Taming the Elusive “Calculated Column” - Logic - Part 1
  18. Taming the Elusive “Calculated Column” - Logic - Part 2
  19. Taming the Elusive “Calculated Column” - Logic - Part 3
  20. Taming the Elusive “Calculated Column” - Logic - Part 4
  21. Taming the Elusive “Calculated Column” - Logic - Part 5
  22. Taming the Elusive “Calculated Column” - Logic - Part 7
  23. Taming the Elusive “Calculated Column” - Logic - Part 6
  24. Taming the Elusive “Calculated Column” - Logic - Part 8
  25. Taming the Elusive “Calculated Column” - Logic - Part 9
  26. Taming the Elusive “Calculated Column” - Logic - Part 10
  27. Taming the Elusive “Calculated Column” - Date and Time - Part 1
  28. Taming the Elusive “Calculated Column” - Date and Time - Part 2
  29. Taming the Elusive “Calculated Column” - Date and Time - Part 3
  30. Taming the Elusive “Calculated Column” - Date and Time - Part 4
  31. Taming the Elusive “Calculated Column” - Referencing Multiple Lines of Text Column
  32. Taming the Elusive “Calculated Column” – Date and Time – Part 5
  33. Taming the Elusive “Calculated Column” – Date and Time – Part 6
  34. Taming the Elusive “Calculated Column” – Date and Time – Part 7
  35. Taming the Elusive "Calculated Column" - Referencing a Multiple Lines of Text Column With Append Text: Part 1
  36. Taming the Elusive "Calculated Column" - Referencing a Multiple Lines of Text Column With Append Text: Part 2
  37. Taming the Elusive "Calculated Column" - Referencing a Multiple Lines of Text Column With Append Text: Part 3
 

Please Join the Discussion

13 Responses to “Taming the Elusive “Calculated Column” – Referencing a Multiple Lines of Text Column With Append Text: Part 1”
  1. Charlie Epes says:

    Hi Dessie:
    Relative to Parts 1, 2 and 3, is this at all possible to add to a List in which the versioning has been ongoing for a year or more? In other words, can I retrofit your solution into my existing List?

    Thanks-

    Charlie Epes

  2. Venkateswara Rao says:

    Hi Dessie,

    Thanks for the post. I have one doubt.

    In the comments I’m able to see the different versions. But I don’t want the name who modified that one …

    What I mean to say is,

    Date Field and Comment is Required for me. i don’t need the name of the person who modified. Any Suggestions please.

    • Venkateswara,
      Just remove the “Modified By” column from the view and you wont see who made the change.

      If you read through the two remaining articles in this series you notice that I mention to remove any columns not needed – this is where you’d remove the modified by column if you dont want to see who made the last change.

      - Dessie

      • Venkateswara Rao says:

        In the views I can uncheck the ” Modified By ” Filed. But when click each item which is having different version… here you will find “Person Name (Date Modified) : Text”

        Here I don’t want the “Person Name”…

        Please let me know if my question is not clear …

        Thanks,
        Rao.

  3. Carole says:

    Can you provide the missing script???? On the view page, add in a CEWP and paste in the following script into its “Source Editor”:

    I wen to the website that you have listed and it seems that all of the old data is gone.

    I need to do what you have described here but without the script can not proceed.

    Thank you.

  4. Carole,
    The post should be updated soon to include the missing script (it did used to be there, honest).

    In the meantime, here’s the script itself:

    <script type="text/javascript">
    /*
    Text to HTML - version 2.1
    Questions and comments: [email protected]
    */
    function TextToHTML(NodeSet, HTMLregexp) {
    var CellContent = "";
    var i=0;
    while (i < NodeSet.length){
    try {
    CellContent = NodeSet[i].innerText || NodeSet[i].textContent;
    if (HTMLregexp.test(CellContent)) {NodeSet[i].innerHTML = CellContent;}
    }
    catch(err){}
    i=i+1;
    }
    }
    // List views
    var regexpTD = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
    TextToHTML(document.getElementsByTagName("TD"),regexpTD);
    </script>
    
    • Carole says:

      Thanks so much for the quick reply. One more question. When I run the code the first time it works fine, but when another entry is made somewhere else in the form then the calc fields show 0. Not sure what I did wrong.

      Caorle

  5. Here you go Dessie… let me google that for you:
    http://sp2010.pathtosharepoint.com/SharePoint-User-Toolkit/Downloads/Forms/AllItems.aspx

    Glad I could be of help :-)
    Mark

  6. Angela Johnson says:

    I realize I’m diverging from this post, but I’d like to do what you describe above, only using a “User or Group” column in my calculated column. Instead of displaying the name, however, it displays “16;#AD\username” – any way to trick Sharepoint into looking it up and displaying the actual person’s name?

  7. Al says:

    The CEWP does not seem to strip out the html from displaying (the brackets and div and such)… I have been over it line by line and can’t figure out why – any ideas what I may be doing wrong? I downloaded the TexttoHTML Lite 2.1.1 from http://sp2010.pathtosharepoint.com/SharePoint-User-Toolkit/Downloads/Forms/AllItems.aspx, and after it initially didn’t work, trimmed out the Calendar Views portion (as that seemed to be the only change between the 2.1 you have listed here and 2.1.1).

Trackbacks

Check out what others are saying about this post...
  1. [...] Part 1, Dessie gave us the first six steps "How to reference a ‘Multiple Lines of Text’ [...]

  2. [...] Part 1 and Part 2 Dessie showed us the first 9 steps in “How to reference a ‘Multiple Lines of [...]




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!