Update Status of Parent/Child List Items

Feb 5, 2010 at 3:24 PM

I have written the code in .NET to use the SharePoint Web Services to update the status of a Parent list and then find all the children list for that parent and then update the status for each child entry (ie Project Parent List and Tasks Child List).  The ID for the Project List is stored in a "ProjectID" field in the Tasks List.

How would I do the same thing using the jQuery Library for SharePoint Web Services?

On the DispForm of a Project you will see a list of all the Tasks associated with that Project at the bottom of the screen.  I would like to put a button on the screen that says "Close Project and Tasks".  If a user clicks that button it should set the status to closed for that Project and the associated Tasks.

This is fairly straightfoward in .NET, how is it using the jQuery Library?

thanks!

Mark

Coordinator
Feb 5, 2010 at 3:51 PM
Edited Feb 5, 2010 at 3:52 PM

Mark:

Here's the basic idea. All Web Service operations which are available (check the docs) are called like this (GetListItems example):

$().SPServices({
   operation: "GetListItems",
   // Force sync so that we have the right values for the child column onchange trigger
   async: false,
   listName: "Project List Name",
   // Filter based on the currently selected parent column's value
   CAMLQuery: "", // Your query
   // Only get the parent and child columns
   CAMLViewFields: "<ViewFields><FieldRef Name='" + opt.relationshipListParentColumn + "' /><FieldRef Name='" + opt.relationshipListChildColumn + "' /></ViewFields>",
   // Override the default view rowlimit and get all appropriate rows
   CAMLRowLimit: 0,
   completefunc: function(xData, Status) {
    $(xData.responseXML).find("faultcode").each(function() {
      ... do stuff ...
    });
});

So since you've already got this working in .NET code, it's really just a translation.  Each Web Service operation takes exactly the same parameters it would anywhere else.  I've just got each operation "wrapped" so that you don't have to worry about soap stuff at all.  I can look at this more for you after my lunch meeting...

M.

Coordinator
Feb 5, 2010 at 8:44 PM
Edited Feb 5, 2010 at 8:59 PM

So, digging a little deeper, I think this is going to be pretty close to what you need.  Caveat emptor: I haven't tested it on anything.

M.

 

var newProjectStatus;
var newTaskStatus;
// Get the Query String values and split them out into the vals array
  var vals = new Object();
  var qs = location.search.substring(1, location.search.length);
  var args = qs.split("&");
  for (var i=0; i < args.length; i++) {
   var nameVal = args[i].split("=");
   var temp = unescape(nameVal[1]).split('+');
   nameVal[1] = temp.join(' ');
   vals[nameVal[0]] = nameVal[1];
  }
  var itemId = vals["ID"];
// Update the project
$().SPServices({
 operation: "UpdateListItems",
 listName: "Project List Name",
 ID: itemId,
 valuepairs: [["Status", newProjectStatus]],
 completefunc: function (xData, Status) {
  // Do some error checking for the update here
  // Update the tasks
  $().SPServices({
   operation: "GetListItems",
   listName: "Task List Name",
   camlQuery: "<Query><Where><Eq><FieldRef Name='ProjectID'/><Value Type='Integer'>" + itemId + "</Value></Eq>",
   completefunc: function (xData, Status) {
    $(xData.responseXML).find("[nodeName=z:row]").each(function() {
     var thisId = $(this).attr("ows_ID");
     $().SPServices({
      operation: "UpdateListItems",
      listName: "Task List Name",
      ID: $(this).attr("ows_ID"),
      valuepairs: [["Status", newTaskStatus]],
      completefunc: function (xData, Status) {
 
 // Do some error checking for the update here
      }
     });
    });
   }
  });
 }
});
Feb 5, 2010 at 10:52 PM

Hey Marc,

 

It worked great first try! You are the man.

I may ping you if I have technical questions about what's going on.

Thanks again for the help, see you next week.

Mark

Coordinator
Feb 5, 2010 at 10:55 PM

Excellent! I can't believe I didn't have some typos or something.

M.