2

I've got an issue where I keep getting

"Exception calling "UpdateListItems" with "2" argument(s): "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."

whenever I call $service.updatelistitems($listname, $xml). I've scoured the Net and see some people having similar issues. My sharepoint list is called Autos and has the Title field renamed to Make and an additional field name Model, both simple string fields.

Does anybody know why I can't update my list? Reading the list works just fine.

    $uri = 'http://myServerName/sandbox/_vti_bin/lists.asmx?wsdl'
    $listName = 'Autos'  # car list
    cls

    # Create the service            
    $service = New-WebServiceProxy -Uri $uri  -Namespace SpWs  -UseDefaultCredential

    # Create xml query to retrieve list.
    $xmlDoc = new-object System.Xml.XmlDocument
    $query = $xmlDoc.CreateElement("Query")
    $viewFields = $xmlDoc.CreateElement("ViewFields")
    $queryOptions = $xmlDoc.CreateElement("QueryOptions")
    $query.set_InnerXml("FieldRef Name='Full Name'")
    $rowLimit = "1000"

    $list = $null
    $service = $null

    try{
        $service = New-WebServiceProxy -Uri $uri  -Namespace SpWs  -UseDefaultCredential
    }
    catch{
        Write-Error $_ -ErrorAction:'SilentlyContinue'
    }

    # Now, we use the service object to retrieve the list.
    if($service -ne $null){
        try{
            $list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
        }
        catch{
            Write-Error $_ -ErrorAction:'SilentlyContinue'
        }
    }

    # $list.data.row
    ($list.data.row).count


    # Get name attribute values (guids) for list and view
    $ndlistview = $service.getlistandview($listname, "")
    $strlistid = $ndlistview.childnodes.item(0).name
    $strviewid = $ndlistview.childnodes.item(1).name

    # Create an xmldocument object and construct a batch element and its attributes.
    $xmldoc = new-object system.xml.xmldocument

    # note that an empty viewname parameter causes the method to use the default view
    $batchelement = $xmldoc.createelement("Batch") # Capital B
    $batchelement.setattribute("onerror", "continue")
    $batchelement.setattribute("listversion", "1")
    $batchelement.setattribute("viewname", $strviewid)

    # Specify methods for the batch post using caml. to update or delete, specify the id of the item,
    # and to update or add, specify the value to place in the specified column
    $xml = ""
    $xml += "<method ID='1' cmd='Update'>" +
            "<field name='ID'>1</field>" +
            "<field name='Title'>Subaru</field>" +
            "<field name='Model'>Outback</field>" +
            "</method>"


    # Set the xml content
    $batchelement.innerxml = $xml

    $ndreturn = $null
    # $ndreturn = $service.updatelistitems($strlistid, $batchelement) # no change using listID
            $ndreturn = $service.updatelistitems($listName, $batchelement)
BenConrad
  • 23
  • 4

0 Answers0