Return to Snippet

Revision: 38592
at October 26, 2011 06:22 by rumremix


Updated Code
function printObject(o){
		var output = '';
		for (property in o) {
		  output += property + ': ' + o[property]+'; ';
		}
		alert(output);
	}




function readThenWrite(){



$().SPServices({
		  operation: "GetListItems",
                  webURL: "/sitepath", /*optional parameter used if list lives in parent site */
		  async: false,
		  listName: "Badge Achievements", /*name of the list */
                  viewName: '{D6ED584C-4673-4B89-B539-FF43D936ABC9}',/*optional to specify view */
                  CAMLRowLimit: 4, /*optional to limit results */
 		  CAMLQuery: '<Query><Where><Eq><FieldRef Name="Author" /><Value Type="User">' + userName + '</Value></Eq></Where></Query>',
		  completefunc: function (xData, Status) {
//printObject(xData);
		 		$(xData.responseXML).find("[nodeName=z:row]").each(function(i) {
		 		arrBadgesAchvd[i] = $(this).attr('ows_Badge').split("#")[1];
					});
				}	
	  	  
		});/*-End SpServices*/


		

    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "Learning Path Completion",
        updates: "<Batch OnError='Continue'>" +
		                "<Method ID='1' Cmd='Update'>" +
		                		"<Field Name='Title'>percDone</Field>" +
		                    "<Field Name='User'>" + userID + "</Field>" +
 		                    "<Field Name='Completed'>" + lpdone + "</Field>" +
		                    "<Field Name='Total'>" + lptotal + "</Field>" +
		                    "<Field Name='ID'>" + docid + "</Field>" +
		                "</Method>" +
		            "</Batch><Where></Where>",
        completefunc: function(xData, Status) {}
        });//End SPSErvices




}/*End readThenWrite*/

Revision: 38591
at January 5, 2011 14:42 by rumremix


Updated Code
function printObject(o){
		var output = '';
		for (property in o) {
		  output += property + ': ' + o[property]+'; ';
		}
		alert(output);
	}




function readThenWrite(){



$().SPServices({
		  operation: "GetListItems",
		  async: false,
		  listName: "Badge Achievements",
                  viewName: '{D6ED584C-4673-4B89-B539-FF43D936ABC9}',
                  CAMLRowLimit: 4,
 		  CAMLQuery: '<Query><Where><Eq><FieldRef Name="Author" /><Value Type="User">' + userName + '</Value></Eq></Where></Query>',
		  completefunc: function (xData, Status) {
//printObject(xData);
		 		$(xData.responseXML).find("[nodeName=z:row]").each(function(i) {
		 		arrBadgesAchvd[i] = $(this).attr('ows_Badge').split("#")[1];
					});
				}	
	  	  
		});/*-End SpServices*/


		

    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "Learning Path Completion",
        updates: "<Batch OnError='Continue'>" +
		                "<Method ID='1' Cmd='Update'>" +
		                		"<Field Name='Title'>percDone</Field>" +
		                    "<Field Name='User'>" + userID + "</Field>" +
 		                    "<Field Name='Completed'>" + lpdone + "</Field>" +
		                    "<Field Name='Total'>" + lptotal + "</Field>" +
		                    "<Field Name='ID'>" + docid + "</Field>" +
		                "</Method>" +
		            "</Batch><Where></Where>",
        completefunc: function(xData, Status) {}
        });//End SPSErvices




}/*End readThenWrite*/

Revision: 38590
at January 5, 2011 14:39 by rumremix


Updated Code
function readThenWrite(){



$().SPServices({
		  operation: "GetListItems",
		  async: false,
		  listName: "Badge Achievements",
                  viewName: '{D6ED584C-4673-4B89-B539-FF43D936ABC9}',
                  CAMLRowLimit: 4,
 		  CAMLQuery: '<Query><Where><Eq><FieldRef Name="Author" /><Value Type="User">' + userName + '</Value></Eq></Where></Query>',
		  completefunc: function (xData, Status) {
		 		$(xData.responseXML).find("[nodeName=z:row]").each(function(i) {
		 		arrBadgesAchvd[i] = $(this).attr('ows_Badge').split("#")[1];
					});
				}	
	  	  
		});/*-End SpServices*/


		

    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "Learning Path Completion",
        updates: "<Batch OnError='Continue'>" +
		                "<Method ID='1' Cmd='Update'>" +
		                		"<Field Name='Title'>percDone</Field>" +
		                    "<Field Name='User'>" + userID + "</Field>" +
 		                    "<Field Name='Completed'>" + lpdone + "</Field>" +
		                    "<Field Name='Total'>" + lptotal + "</Field>" +
		                    "<Field Name='ID'>" + docid + "</Field>" +
		                "</Method>" +
		            "</Batch><Where></Where>",
        completefunc: function(xData, Status) {}
        });//End SPSErvices




}/*End readThenWrite*/

Revision: 38589
at January 5, 2011 14:23 by rumremix


Updated Code
function readThenWrite(){

		$().SPServices({
		  operation: "GetListItems",
		  async: false,
		  listName: "Extended User Profile",
                  viewName: '{D6ED584C-4673-4B89-B539-FF43D936ABC9}',
                  CAMLRowLimit: 4,
 		  CAMLQuery: "<Query><Where><And><Eq><FieldRef Name='GUID0' /><Value Type='Text'>"+lessonID+"</Value></Eq><Eq><FieldRef Name='UserID' /><Value Type='Text'>"+userID+"</Value></Eq></And></Where></Query>",
		  completefunc: function (xData, Status) {
				var len = $(xData.responseXML).find("[nodeName=z:row]").length;
		    if(len == 0){
		    		$('#complete').click(function(){
							complete($(this));
						});      			
						$('#complete').removeClass('btn_completed').addClass('btn_not_completed');	
						$('#complete .complete_rollover').text('Mark this lesson complete in your learning path.');

						$('#complete .btn').fadeIn();
		    }else{
		    	$('#complete').removeClass('btn_not_completed').addClass('btn_completed');
		    	$('#complete .btn').fadeIn(); 
		    	$('#complete .complete_rollover').text('This lesson has been completed.');
		    	$('#startExt').attr("href", $('#startExt').attr("href") + "&completed=true");
		    	
		    	
		    }
		  }
		  
		});/*-End SpServices*/



    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "Learning Path Completion",
        updates: "<Batch OnError='Continue'>" +
		                "<Method ID='1' Cmd='Update'>" +
		                		"<Field Name='Title'>percDone</Field>" +
		                    "<Field Name='User'>" + userID + "</Field>" +
 		                    "<Field Name='Completed'>" + lpdone + "</Field>" +
		                    "<Field Name='Total'>" + lptotal + "</Field>" +
		                    "<Field Name='ID'>" + docid + "</Field>" +
		                "</Method>" +
		            "</Batch><Where></Where>",
        completefunc: function(xData, Status) {}
        });//End SPSErvices




}/*End readThenWrite*/

Revision: 38588
at January 5, 2011 14:21 by rumremix


Initial Code
function readThenWrite(){

		$().SPServices({
		  operation: "GetListItems",
		  async: false,
		  listName: "Extended User Profile",
                  viewName: '{D6ED584C-4673-4B89-B539-FF43D936ABC9}',
                  CAMLRowLimit: 4,
 		  CAMLQuery: "<Query><Where><And><Eq><FieldRef Name='GUID0' /><Value Type='Text'>"+lessonID+"</Value></Eq><Eq><FieldRef Name='UserID' /><Value Type='Text'>"+userID+"</Value></Eq></And></Where></Query>",
		  completefunc: function (xData, Status) {
				var len = $(xData.responseXML).find("[nodeName=z:row]").length;
		    if(len == 0){
		    		$('#complete').click(function(){
							complete($(this));
						});      			
						$('#complete').removeClass('btn_completed').addClass('btn_not_completed');	
						$('#complete .complete_rollover').text('Mark this lesson complete in your learning path.');

						$('#complete .btn').fadeIn();
		    }else{
		    	$('#complete').removeClass('btn_not_completed').addClass('btn_completed');
		    	$('#complete .btn').fadeIn(); 
		    	$('#complete .complete_rollover').text('This lesson has been completed.');
		    	$('#startExt').attr("href", $('#startExt').attr("href") + "&completed=true");
		    	
		    	
		    }
		  }
		  
		});/*-End SpServices*/


function updateLPPerc(docid){
    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "Learning Path Completion",
        updates: "<Batch OnError='Continue'>" +
		                "<Method ID='1' Cmd='Update'>" +
		                		"<Field Name='Title'>percDone</Field>" +
		                    "<Field Name='User'>" + userID + "</Field>" +
 		                    "<Field Name='Completed'>" + lpdone + "</Field>" +
		                    "<Field Name='Total'>" + lptotal + "</Field>" +
		                    "<Field Name='ID'>" + docid + "</Field>" +
		                "</Method>" +
		            "</Batch><Where></Where>",
        completefunc: function(xData, Status) {}
        });//End SPSErvices
}//End Function



}/*End readThenWrite*/

Initial URL

                                

Initial Description
Just syntax examples here. First block reads, second writes. Top function just a debugging helper.

Using jquery 1.5, $(xData.responseXML).find("nodeName=z:row]").each(function(i)... may need to be written as
$(xData.responseXML).find("nodeName='z:row']").each(function(i)... with single quotes around 'z:row'.

Initial Title
reading and writing list data in SharePoint 2010 using SPServices

Initial Tags
javascript, list, jquery, sharepoint

Initial Language
jQuery