[Solved]: New-WebServiceProxy / GetListItems Excessive Lookup Issue

Recently, while trying to use New-WebServiceProxy to automate some SharePoint form entries, I ran into a lookup issue.

First, I got this rather generic error: Exception calling "GetListItems" with "7" argument(s): "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown." .

So I dug deeper with a try/catch.

if($service -ne $null){
		$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
		catch \[System.Web.Services.Protocols.SoapException\] {
		Write-Host "Exiting"

The resulting error stated: The query cannot be completed because the number of lookup columns it contains exceeds the lookup column threshold enforced by the administrator.

Upon searching Google, many people suggested increasing the threshold in Central Administration, but there were two issues with this

  1. I'm not a Farm Admin (fortunately)
  2. Marc D. Anderson pointed out some very good reasons for not increasing the threshold. The SharePoint farm I'm working with is already slow, so I wouldn't even want to ask the Admin to up the limit.

Some folks suggested using a different view, other than the default, but even minimal views didn't work. Ultimately, I limited the ViewFields to just the ones I needed.

# Create xml query to retrieve list.
$xmlDoc = new-object System.Xml.XmlDocument
$query = $xmlDoc.CreateElement("Query")
$viewName = "" # Default
$vfxml = "<ViewFields>" +
        "<FieldRef Name='Title' />" +
		"<FieldRef Name='Description' />" +
		"<FieldRef Name='Status' />" +
$viewFields = $xmlDoc.CreateElement("ViewFields")
$queryOptions = $xmlDoc.CreateElement("QueryOptions")
$query.set\_InnerXml("FieldRef Name='Full Name'") 
$rowLimit = "1"

$list = $null; $service = $null
$service = New-WebServiceProxy -Uri $uri  -Namespace SpWs  -UseDefaultCredential
$list = $service.GetListItems($listName, $viewName, $query, $viewFields, $rowLimit, $queryOptions, "")

This is just a snippet of the fields I used, and fortunately, the total number of fields I needed didn't have more than 8 lookups. If your script needs to modify more than 8 lookups, then it's likely that you'll need to up the lookup limit or divide the Add/Update into two calls.