I am trying to get an item in a SharePoint list using a CAML query so that I can update it. I am using data in a CSV file but when I run the script, it's failing on Get-PnPListItem. Based on some research I believe I'm getting this error because I have an error with the query. Does anyone know what the error is? The description field may be null in CSV which is why there's a conditional. Title and Location always have a value.
$data= Import-Csv "myPath\data.csv"
foreach ($item in $data) {
$query = "<View><Query><Where><And><Eq><FieldRef Name='Title'/><Value Type='Text'>" + $item.Title + "</Value></Eq><Eq><FieldRef Name='Location'/><Value Type='Text'>" + $item.Location + "</Value></Eq>"
if($item.Description -eq $null) {
$query += "<IsNull><FieldRef Name='Description'/></IsNull>"
} else {
$query += "<Eq><FieldRef Name='Description'/><Value Type='Text'>" + $item.Description + "</Value></Eq>"
}
$query += "</And></Where></Query></View>"
$spListItem = Get-PnPListItem -List "My SP List" -Query $query
}
Here is an example of what the query string looks like:
<View><Query><Where><And><Eq><FieldRef Name='Title'/><Value Type='Text'>Grand Canyon</Value></Eq><Eq><FieldRef Name='Location'/><Value Type='Text'>Arizona</Value></Eq><Eq><FieldRef Name='Description'/><Value Type='Text'>National Park</Value></Eq></And></Where></Query></View>
I have verified internal names are properly spelled. All field types in query are single line of text