MOSS: Multiple Line Text Field - Consolidate appended text from versions for use in SharePoint Workflow - SharePoint Development & Administration + InfoPath

Sunday, January 23, 2011

MOSS: Multiple Line Text Field - Consolidate appended text from versions for use in SharePoint Workflow

When playing around with "Multiple Lines of text" fields that were configured to append changes to the previous versions. I found that when trying to use the value in the field in a workflow created using SharePoint Designer, it would only find the value entered into the field in the most recent version of the item even if the field was left blank. For example, if you create a new list item with some text in the multiple lines of text field, the workflow will pick up the value as expected. If you then make a change to the item, but leave the appended text field blank this time, the version is incremented and the most recent version will not have a value for this field. The result in the workflow created using SharePoint Designer was that it would only see the value in the field of the most recent version. I needed all entries appended to the field, and not just the most recent by consolidating the text from each version.

I achieved this using a workaround solution, as I was not able to access data from past versions of a list item without writing or installing custom workflow extensions for SharePoint Designer. My solution was to create a hidden text field in the list, which was updated using a separate workflow each time a change is made to the list item to replicate the "Append Text" functionality.

I left the original multiple line text field configured to append text to previous versions so that the historic entries of the text field could still be displayed in the standard display or edit form (the hidden field is not visible on edit/display fields as it should be manually edited by a user). The process of the workflow to append the new text to the hidden field was quite simple. I first used the "build a dynamic string" action to create a workflow variable that contained the past entries as well as the newly updated entry, including the modify date and modified by user for reference purposes. The next and final step is to update the hidden field with the value in the workflow variable only of the value in the two are not already equal. If they are equal when the worklow is initiated, the workflow will do nothing (stop). This is to help prevent the workflow from entering an indefinate loop for environments with SP1 or no service packs installed. This is because the process of updating the hidden field in the current list item can trigger a new instance of the workflow creating an endless loop. Incorporating a simple test into the logic to only update the hidden field if the new value is not equal to the existing value will prevent this from happening.

Now, when I need to use the the contents of the appended text field in a workflow, I can use the contents of the hidden field, which will contain the equivalent to the historic appended text field entries and not just the value from the most recent version.



Share this article:
Stumble This Delicious
submit to reddit

No comments:

Post a Comment