{"id":1438,"date":"2014-01-20T05:10:14","date_gmt":"2014-01-20T05:10:14","guid":{"rendered":"https:\/\/poiseddevelopers.com\/reality-tech\/?p=1438"},"modified":"2024-05-02T07:10:11","modified_gmt":"2024-05-02T07:10:11","slug":"the-sharepoint-internals-behind-an-append-text-field","status":"publish","type":"post","link":"https:\/\/poiseddevelopers.com\/reality-tech\/the-sharepoint-internals-behind-an-append-text-field\/","title":{"rendered":"The SharePoint internals behind an Append text field"},"content":{"rendered":"<h2>SharePoint internals of the Append text field<\/h2>\n<p>In configuring a SharePoint field, there\u2019s an option to \u201cAppend Changes to Existing Text\u201d for Multi-line text fields. This setting requires versioning be enabled. Let\u2019s delve into why versioning must be enabled for this feature to be enabled.<\/p>\n<p>In a nutshell, SharePoint puts the latest value within the property bag, which you can see if you grab the SPItem object, and dump the read-only SPItem.xml. First let\u2019s examine in PowerShell.<\/p>\n<pre lang=\"php\"># let's get the web:\r\n$web=Get-SPWeb http :\/\/SharePoint\/sites\/Site\/web\r\n \r\n# let's get the list:\r\n$list = $web.Lists[\"Name of List\"]\r\n \r\n# let's get the SPItem:\r\n$q=$list.GetItemById(4567)\r\n \r\n#Let's set the internal field name for later reference:\r\n$FName = \"Internal Field Name\"\r\n<\/pre>\n<p>A more elegant way is by addressing by URL directly:<\/p>\n<pre lang=\"php\">$url=\"http :\/\/SharePoint\/sites\/Site\/web\/Listname\/4567_.000\"\r\n$item = $web.GetListItem($url)\r\n<\/pre>\n<p>Then we can peek into the property bag:<\/p>\n<pre lang=\"php\">$item.xml\r\n<\/pre>\n<p>It is worth noting there are times when SharePoint does not put the latest value in the property bag. In fact the property is absent altogether, although the versions continue to capture the append text. One theory is that this occurs to SP2007 lists that have been upgraded. If you experience this behavior, read below for accessing all of the append text.<\/p>\n<p>But where are the previous appends? How can we see them? The trick is to walk through the versions, grabbing the version SPItem, and then grab the field value.<\/p>\n<pre lang=\"php\">foreach ($v in $item.versions)\r\n{\r\n $v.get_Item($FName)\r\n}\r\n<\/pre>\n<p>In C# we extract in a function such as this:<\/p>\n<pre lang=\"php\">public static string GetVersionedMultiLineTextAsPlainText(int ID, string field,SPList list)\r\n {\r\n     SPListItem item = list.GetItemById(ID);\r\n     StringBuilder sb = new StringBuilder();\r\n     foreach (SPListItemVersion version in item.Web.Lists[item.ParentList.ID].Items[item.UniqueId].Versions)\r\n     {\r\n         SPFieldMultiLineText CommentsField = version.Fields.GetFieldByInternalName(field) as SPFieldMultiLineText;\r\n         if (CommentsField != null)\r\n         {\r\n             string comment = CommentsField.GetFieldValueAsText(version[field]);\r\n             if (comment != null &amp;&amp; comment.Trim() != string.Empty)\r\n             {\r\n                 sb.Append(\"\");\r\n                 sb.Append(version.CreatedBy.User.Name).Append(\" (\");\r\n                 sb.Append(version.Created.ToString(\"MM\/dd\/yyyy hh:mm tt\"));\r\n                 sb.Append(\") \");\r\n                 sb.Append(comment);\r\n             }\r\n         }\r\n     }\r\n     return sb.ToString();\r\n }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SharePoint internals of the Append text field In configuring a SharePoint field, there\u2019s an option to \u201cAppend Changes to Existing Text\u201d for Multi-line text fields. This setting requires versioning be enabled. Let\u2019s delve into why versioning must be enabled for this feature to be enabled. In a nutshell, SharePoint puts the latest value within the [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":1439,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[28,14],"tags":[],"class_list":["post-1438","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c","category-sharepoint-development-solutions"],"acf":[],"_links":{"self":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/comments?post=1438"}],"version-history":[{"count":6,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1438\/revisions"}],"predecessor-version":[{"id":1448,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1438\/revisions\/1448"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media\/1439"}],"wp:attachment":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media?parent=1438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/categories?post=1438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/tags?post=1438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}