Jesse Roper
Jesse Roper

Reputation: 1309

Programmatically changing values of Sharepoint 2007 lists

I have an ID field in one of my lists which may change and needs to be updated in list items in various lists. I need to know if this is possible. I know I could accomplish it using C# and Sharepoint Services, but I have the need to do it through javascript. Basically, I have 5 lists and on changing the value of a client ID in one of those lists and clicking "OK", I need to iterate through the other 4 lists and change that value for any items that may exist in those lists with that ClientID.

Any assistance is greatly appreciated!

Upvotes: 1

Views: 1851

Answers (1)

pixelbobby
pixelbobby

Reputation: 4440

I work for a gov't organization and we have a large-scale SharePoint 2007 Farm. We use jQuery and SPServices libraries to do AJAX calls to various SharePoint Lists.

For your specific need you would do a series of web requests using something like the code example below.

Here's the API for updating a SharePoint List:
http://spservices.codeplex.com/wikipage?title=UpdateListItems&referringTitle=Lists

Here's a code example:

Params

batchCmd: "Update",
valuepairs: 
    [["Title", "New Title Value"], 
    ["Body", "Here is a the new text for the body column."]], ID: 1234,

XML

<Batch OnError='Continue'>
  <Method ID='1' Cmd='Update'>
    <Field Name='Title'>New Title Value</Field>
    <Field Name='Body'>Here is a the new text for the body column.</Field>
    <Field Name='ID'>1234</Field>
  </Method>
</Batch>

JS

$(divId).html(waitMessage).SPServices({
    operation: "UpdateListItems",
    listName: testList,
    ID: ID,
    valuepairs: [["Title", now]],
    completefunc: function (xData, Status) {
        var out = $().SPServices.SPDebugXMLHttpResult({
            node: xData.responseXML,
            outputId: divId
        });
        $(divId).html("").append("<b>This is the output from the UpdateListItems operation:</b>" + out);
        $(divId).append("<b>Refresh to see the change in the list above.</b>");
    }
});

Upvotes: 1

Related Questions