CopyIntoItems to update existing document

Jun 11, 2013 at 4:45 PM
I am using the following code to create a new InfoPath document and this is working fine:
        var decoded = data;
    var encoded = window.btoa(decoded);
    
    $().SPServices({
            operation: "CopyIntoItems",
            webURL: wurl,   
            async: false,
            SourceUrl: url,
            Stream: encoded,
            DestinationUrls: [url],
            completefunc: function(xData, Status) {
                                        
            }
        });
I am now trying to update this document. I need to update and keep version history. This is what I have tried without success. In this example I am trying to change the Company Name field.
$().SPServices({
    operation: "GetItem",
    async: false,
    webURL: wurl,
    Url: url,
    completefunc: function (xData, Status) {
        var out = xData.responseXML.documentElement.childNodes[0].childNodes[0].childNodes[2].textContent;
        var decoded = window.atob(out);
        decoded = decoded.replace(/<my:company>.*<\/my:company>/i,'<my:Company>'+company+'</my:Company>');
        var encoded = window.btoa(decoded);
    
    $().SPServices({
            operation: "CopyIntoItems",
            webURL: wurl,   
            async: false,
            Source: url,
            Stream: encoded,
            DestinationUrls: [url],
            completefunc: function(xData, Status) {
                    var out = $().SPServices.SPDebugXMLHttpResult({
                        node: xData.responseXML
                    });
                    $('#data').html(out);
                    alert("Status=" + Status + " XML=" + xData.responseXML);    
                    
            }
        });

    }
});
For "Status" I get Success. In the XML response I get CopyResult: ErrorCode - Unknown, ErrorMessage - Value does not fall within the expected range. Any ideas?
Jun 11, 2013 at 11:05 PM
Maybe I'm going about this the wrong way. I just tried the following and seems to almost work..
                $().SPServices({
                        operation: "UpdateListItems",
                        async: false,
                        listName: Lname,
                        ID: id,
                        valuepairs: [["Company", "New Company"]],
                        completefunc: function (xData, Status) {
                            var out = $().SPServices.SPDebugXMLHttpResult({
                                node: xData.responseXML
                            });
                            $('#data').html(out);
                            alert("Status=" + Status + " XML=" + xData.responseXML);    
                        }
                    });
                    
                    });
I get "Status" success and no ErrorCode. In SharePoint the document shows that it was updated and a new version is created but the change is not made. Any help would be greatly appreciated..
Coordinator
Jun 12, 2013 at 12:58 AM
Edited Jun 12, 2013 at 5:18 AM
When you call UpdateListItems, the return value contains the items as it looks after the update. If you look at xData.responseText, you should be able to see whether the update has occurred. If there's no error, it probably has.

M.
Jun 12, 2013 at 3:05 AM
There is no error. I get ErrorCode 0x00000000. But the field is not updated in SharePoint. The file is modified and shows a new Modified date/time and a new version in version history. I can't figure out why the field is not being updated.
Coordinator
Jun 12, 2013 at 5:19 AM
Edited Jun 12, 2013 at 9:10 PM
You should look at the returned item, though, to see what's going on. I recommend using Firebug to look at the Net traffic.

M.
Jun 12, 2013 at 6:14 AM
I checked with Firebug. Here is the post:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
  <UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <listName>Quotes</listName>
      <updates>
        <Batch OnError="Continue">
          <Method ID="1" Cmd="Update">
            <Field Name="Company">New Company</Field>
            <Field Name="ID">79615</Field>
          </Method>
        </Batch>
      </updates>
    </UpdateListItems>
  </soap:Body>
</soap:Envelope>
But in the response back the field is not changed and the original data is written back to the file causing a new version. I really appreciate the help. What else should I be looking for?
Coordinator
Jun 12, 2013 at 9:12 PM
Are you sure that the InternalName of the column you want to update is Company? If it is, you should see "ows_Company" in the results.

Also, do you need to check the item out before the update?

M.