This project has moved and is read-only. For the latest updates, please go here.

Newbie - Issue with Sharepoint SP Services GetListItems

Sep 27, 2010 at 8:08 PM

Hello there,

I am using JQuery and SPServices to develop a script on one of my sharepoint sites. I am using the below function.

function PreSaveItem(){ //var uid = document.getElementsByTagName('Title');var uid = getFieldValue("Title", "edit"); //alert(uid); var q ='<Query><Where><Eq><FieldRef Name="Floor_x0020_Space"/><Value Type="Text">'+uid+'</Value></Eq></Where></Query>'; alert('query ->' +q); //var q="<Query><OrderBy><FieldRef Name='Start' Ascending='FALSE'/></OrderBy><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>+uid+</Value></Eq></Where></Query>"; $().SPServices({ operation:'GetListItems',             listName:'{29794E4F-2515-4DF9-8D3B-9FFFE922247B}',             CAMLViewFields:'<ViewFields><FieldRef Name="Floor_x0020_Space"/></ViewFields>',             CAMLQuery: q,             CAMLRowLimit:10,             CAMLQueryOptions:'<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions>',                 completefunc: SuccessFunc,             error: ErrorFunc,             contentType: "text/xml; charset=\"utf-8\""   });   var resultCount = $(result.responseXML).find("[nodeName=rs:data]").attr("ItemCount"); //alert("returnValue->" + resultCount); }

 function SuccessFunc(result){ alert("success->" + result.responseText); alert("Count->" + $(result.responseXML).find("[nodeName=rs:data]").attr("ItemCount")); var resultCount = $(result.responseXML).find("[nodeName=rs:data]").attr("ItemCount"); if(resultCount=='0'){ alert('There is no record with the same UID number'); returnValue = false; }else{ alert('UID already present, please try again'); returnValue = true; } }

function ErrorFunc(result){ alert("Error->" + result.responseText); }


The issue I am having is, in the getListItems... I need to add a condition based on the vlaue of a node and pop-up an error message. But he function seems to be asynchronous and the GetList items does not wait until by SuccessFunc finishes. Is there a way we can put a lock or a wait statement? I could use some help here.



Sep 27, 2010 at 10:09 PM
This is an easy one! There's an asynch option on SPServices. Set it to false and you should be good to go. M.
Sep 27, 2010 at 10:12 PM

Thanks a lot Marc.

I am new to this Tool hence, trying to learn few stuff. Thanks for your help.