Wednesday, November 10, 2010

"Append changes to existing text" feature of a multi-line textbox

How to work around the "append changes to existing text" feature of a multi-line textbox

Tags:

I love to use the multi-line text field in a SharePoint list or library. It is great for things like comments, status updates, notes and any other type of data that might require several lines of text. This column type even has a really cool feature that allows you to “Append Changes to Existing Text”. This feature will store ALL the changes to the field and display a historical list on the Edit or View pages.

clip_image002

Pretty cool! Right? Not so fast. This feature has some annoying drawbacks as well.

The Downside

There are two major side effects to turning the “Append Changes…” feature on.

1. It records all updates even blanks. If you edit the list item and only make a change to any field other than the multi-line text field it will store a blank in the history.

clip_image004

2. It will not display the current text in a list view. You only see a link that reads “View Entries…”.

clip_image006

A Common Approach

A common way I have seen this issue tackled is by creating a XSLT data view in SharePoint Designer. I will not cover this approach in detail, but the basic steps are:

1. Create a new Web Part page.

2. Add the desired list web part to the page.

3. In SharePoint Designer convert the web part into an XSLT Data View.

clip_image008

I do not care for this solution because it only address one of my gripes. It does show the most recent value entered into the multi-line textbox (Issue #2), but if that entry happens to be blank (Issue #1) it will display that as well. See the pictures above. Test Entry 2 displays the text that was entered, but Test Entry 1 shows blank. I want it to retain all the changes I have made and in the list view only display the last text that was entered.

My Solution

My approach utilizes a custom workflow to check for changes, but before we create the workflow we need to make some changes to your list.

1. Add a second multi-line textbox column. Call this one “Current Status” and make sure that the “Append Changes..” option is set to NO. Also, ensure that the “add to default view” is not checked.

2. Mark the new column as hidden. (This will prevent it from showing up in the Add / Edit / View pages)

a. Go to List Settings >> Advanced Settings and make sure the “Allow management of content types?” is YES.

b. In the List Settings page click on the content type to access its settings page.

c. Under the Column section click on “Current Status”.

d. Change the Column Settings to Hidden (Will not appear in forms).

3. Change the default view to show the “Current Status” column in place of the “Status” column.

a. Under the List Settings go to the Views section and click on the default view.

b. Uncheck “Status” and check the box next to “Current Status”. (You can also change the column order if needed)

Now that the list is configured properly we can create the new workflow.

1. Open SharePoint Designer to the desired site and click File >> New >> Workflow.

2. Name the workflow “Update Current Status” and select our list.

3. In the workflow start options ensure that only the boxes for “when a new item is created” and “whenever an item is changed” are checked.

clip_image010

4. Click Next.

5. On the next screen click Variables.

6. Add a new string variable named vRegExp.

clip_image012

7. In the Step Name field rename “Step 1” to “Initialize Variable”.

8. Leave the Conditions section blank.

9. Under Actions select “Build Dynamic String”.

10. Set our newly created variable “vRegExp” to the string “

.+
” (no quotes and it is case sensitive).

clip_image014

11. On the right hand column click the link to “Add workflow step”.

12. In the Step Name field rename “Step 2” to “Update Status”.

13. Under Condition select “Compare Test fields”.

14. Set the condition to “If Status matches regular expression Variable: vRegExp”.

15. Under the Actions select “Set Field in Current Item”.

16. Set the action to “Set Current Status to Status”.

clip_image016

17. Click Finish and exit out of SharePoint Designer.

Now try and update your list items and see what happens. If you enter a status then it will show up in the list view. If you update the item and don’t enter a status then the list view retains the last entry.

Conclusion

This solution uses the Status field with it’s “Append Changes…” feature in the Add / Edit / View forms, and uses the Current Status field for the list view to display the most recent update. A custom workflow was created in SharePoint Designer to check when the Current Status field needed to be updated.

**NOTE: It can take a few seconds for the workflow to run and update the field

8 comments:

  1. This seems to address the problem I am trying to solve - however, in Step 10 I cannot tell what the variable is to be set to as the text breaks up and the none of the picture are available for me to view. Could you repeat what the variable needs to be set to?

    ReplyDelete
  2. Hi,
    I am not able to see your embeded images....

    ReplyDelete
  3. Hi. I have tried this and as far as I can see the blank line is still created if the record is opened and closed with no edit made. This is evident when the list is exported to Excel and the field shows text when a new entry is made, but if the record is opened in edit mode then close with no change, the data refreshed, then the text disappears.
    Have I done something wrong?

    ReplyDelete
  4. Hi Kim,
    Did you ever find the missing code from step 10?
    Thanks

    ReplyDelete
  5. I don't know if anyone is still visiting this article or reading the comments/updates.
    Would like to inform anyone that the instruction stated in the article is straight-forward and it worked for me.

    The vRegExp variable is = .+
    And this is a string that represent a regular expression.
    The Status Field is matched against this regular expression. If there is any added entry in the Status Field, then it will match with the regular expression. Afterwards, the flow sets the Current Status Field value = to Status Field value which is the newly added entry.

    Hope this helps.

    ReplyDelete
    Replies
    1. How would you construct the workflow in SPD2013? I'm struggling with this - my workflow always suspends with the following: RequestorId: 5b849db2-caa1-e170-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.ArgumentNullException: Value cannot be null. Parameter name: input at System.Text.RegularExpressions.Regex.IsMatch(String input) at System.Activities.CodeActivity`1.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) Exception from activity IsEqualString DynamicActivity If Update Column Update Comments Sequence Flowchart Sequence AddComment.WorkflowXaml_0c217ef8_ae0c_4bd0_81d2_063707d8c4d8

      Delete
    2. All good stuff but I am using SPD 2013 and building a dynamic string is no longer available. So how do I set the vRegExp variable to the regular expression .+

      Delete
  6. Enable version history on the list. More information documented about this online @

    http://www.systemsabuse.com/2014/06/23/editing-a-list-item-in-sharepoint-2010-causes-my-appended-column-data-to-disappear-or-get-overwritten/

    ReplyDelete