0

In our Sharepoint 2010 site, I've created a list with a multi line column. I try to extract all lines from this field but receive only the last entry. This field is used to put comments of users:

Sharepoint comments

$Web = Get-SPWeb http://sharepoint-host

$list = $web.Lists["Demo List"]

$query = New-Object Microsoft.SharePoint.SPQuery

$query.RowLimit = 10

$query.Query = '<Where><Eq><FieldRef Name="ID" /><Value Type="Number">4537</Value></Eq></Where><'

$items = $list.GetItems($query)

foreach($item in $items){
    Write-Host "Activity ID : " $item.ID "-" $item["my-multi-line-item"]
  }

In this case it returns only the comment of Anne. What is the correct way to get all lines?

  • Hmm.. I tried to reproduce your issue on my environment, but everything is working fine. I could get all lines on multiple lines of text fields (both the plain and rich text). – AWJ Dec 1 '16 at 9:23
  • @AWJ Thanks for reproducing. See updated question. I only get the most recent comment. – Citizen SP Dec 1 '16 at 9:46
  • I have used your script on, multiline filed , in all types (Plan and rich). It's working properly. May be its because you are using 2010, actually i have test it on SharePoint 2013 – Akshay Dattatray Nangare Dec 1 '16 at 9:50
  • What is the column type of the comment field? Is it really a multiple lines of text? – AWJ Dec 1 '16 at 9:51
  • @AWJ The column type is 'multiple lines of text' with append text enabled. – Citizen SP Dec 1 '16 at 10:47
2

Your list has versioning turned on. Also the multi line field has "Append only changes" setting enabled. So thats why you are getting only the latest value in the field.

enter image description here

Try with below code:

$Web = Get-SPWeb http://sharepoint-host

$list = $web.Lists["Demo list"]

$query = New-Object Microsoft.SharePoint.SPQuery

$query.RowLimit = 10

$query.Query = '<Where><Eq><FieldRef Name="ID" /><Value Type="Number">4537</Value></Eq></Where>'

$items = $list.GetItems($query)

foreach($item in $items){

    $VersionData = ''
    foreach($version in $item.Versions)
    {    
            $VersionData+= $version["Comments"]             
    }    
    Write-Host $VersionData
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.