I have been working with GetListItems, and found it to be very reliable, and easy to implement. One thing I'm trying to figure out is how to handle when there are no items in the list matching the query. It seems like when there are no matches, the alert(xData.responseText); is never fired. I have tried using ItemCount, but it seems to be too far into the function to work. Any guidance would be great
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Personnel",
CAMLViewFields: "<ViewFields>" +
"<FieldRef Name='EmployeeID' />" +
"<FieldRef Name='FirstName' />" +
"<FieldRef Name='LastName' />" +
"<FieldRef Name='Agency' />" +
"<FieldRef Name='FullName0' />" +
"<FieldRef Name='PayRate' />" +
"</ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='EmployeeID'/><Value Type='Text'>" + empID + "</Value></Eq></Where><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy></Query>",
CAMLRowLimit: 1,
completefunc: function (xData, Status) {
$(xData.responseXML).find("[nodeName=z:row]").each(function()
{
alert(xData.responseText);
alert(xData.responseXML.xml);
var validID = $(this).attr("ows_ID");
var empBadgeID = $(this).attr("ows_EmployeeID");
var empFirst = $(this).attr("ows_FirstName");
var empLast = $(this).attr("ows_LastName");
var empAgency = $(this).attr("ows_Agency");
var empFullName = $(this).attr("ows_FullName0");
var empPayRate = $(this).attr("ows_PayRate");
//alert(empFullName);
//$("#txtFullName").val = empFullName();
//$("#lblFullName").text = $(this).attr("ows_FullName");
$("#txtFullName").val(empFullName);
$("#txtLastName").val(empLast);
$("#txtFirstName").val(empFirst);
$("#txtAgency").val(empAgency);
$("#txtPayRate").val(empPayRate);
//var HTML = "<li>" + "Badge ID: " + $(this).attr("ows_EmployeeID") + "</li>" + "<li>" + "First Name: " + $(this).attr("ows_FirstName") + "</li>" + "<li>" + "Last Name: " + $(this).attr("ows_LastName") + "</li>" + "<li>" + "Agency: " + $(this).attr("ows_Agency") + "</li>";
//$("#mydiv").append(HTML);
//$('#mydiv').dialog('open');
if(Status == "success")
{
var itemCount = $(xData.responseXML).find("[nodeName=rs:data]").attr("ItemCount");
if(itemCount == '1')
{
alert("found a valid record")
}
else
{
alert("nothing to see here");
}
}
else
{
alert("something we wrong!");
}
});
}
});
}