carbontracking
carbontracking

Reputation: 1089

Looking for a really simple example of UpdateListItems for SPservices with Sharepoint 2007

I'm just getting into SPServices for Sharepoint, seems like it could be the business for my needs, i.e. programatically updating values in a list.

As a test, I've tried the following code to update the Title column of a list, named jQueryList, with one single row (ID=1).

<script src="..../js/jquery.SPServices-0.7.1a.min.js" type="text/javascript"></script>
<script src="..../js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$(#inhere).html(waitMessage).SPServices({
    operation: "UpdateListItems",
    listName: jQueryList,
    ID: 1,
    valuepairs: [["Title", "eggs"]],
    completefunc: function (xData, Status) {
        var out = $().SPServices.SPDebugXMLHttpResult({
            node: xData.responseXML,
            outputId: inhere
        });
        $(#inhere).html("").append("<b>This is the output from the UpdateListItems operation:</b>" + out);
        $(#inhere).append("<b>Refresh to see the change in the list above.</b>");
    }
});
}
</script>
<div id="inhere">
</div>

I've put this in CEWP at the bottom of my list jQueryList but it doesn't update the value in my row. Apologies about the totally newbie style of the question, but if anyone has any pointers, I'd appreciate it greatly. Note : I get the ID value from displaying the ID column in the default view.

Best regards / Colm

Upvotes: 0

Views: 7605

Answers (1)

carbontracking
carbontracking

Reputation: 1089

What comes below works fine on a list in the same subsite, I'll have to dig a bit more to see how to do this for a list on a separate subsite.

<script src="http://ccs.xxx.corp/sites/TDP_SCS/SiteAssets/js/jquery-1.8.2.js" type="text/javascript"></script>
<script src="http://ccs.xxx.corp/sites/TDP_SCS/SiteAssets/js/jquery.SPServices-0.7.2.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$().SPServices({
    operation: "UpdateListItems",
    async: false,
    batchCmd: "Update",
    listName: "jQueryList",
    ID: 1,
    valuepairs: [["Title", "eggs & ham"]],
    completefunc: function (xData, Status) {
        alert("Dang");
    }
});
});
</script>

Upvotes: 2

Related Questions