Streamline variable match

Working with SharePoint list and JavaScript I am using CAML Query to retrieve data from a SharePoint list ie (Employee name) then SPServices to get the current logon user, I now need a fast way to compare the two and populate that users data to a custom form. i have a working code for this but the list has 4000 entries and is timing out on the server. Is there a more efficient way of comparing?


$(document).ready(function() {
        //The Web Service method we are calling, to read list items we use 'GetListItems'
        var method = "GetListItems";
       
        //The display name of the list we are reading data from
        var list = "EmployeeData2";

       
        var fieldsToRead =     "<ViewFields>" +
                                            "<FieldRef Name='ID' />" +
                                            "<FieldRef Name='Supervisor' />" +
                                                "<FieldRef Name='Pay' />" +
                                                "<FieldRef Name='Location' />" +
                                "<FieldRef Name='Email' />" +
                                "<FieldRef Name='Employee' />" +
                                "<FieldRef Name='FirstName' />" +
                                "<FieldRef Name='LastName' />" +
                                "<FieldRef Name='City' />" +
                            "</ViewFields>";
                           
       
        var query = "<Query>" +
                        "<Where>" +
                            "<Neq>" +
                                "<FieldRef Name='ID'/><Value Type='Number'>0</Value>" +
                            "</Neq>" +
                        "</Where>" +
                        "<OrderBy>" +
                            "<FieldRef Name='ID'/>" +
                        "</OrderBy>" +
                    "</Query>";

        //Here is our SPServices Call where we pass in the variables that we set above
        $().SPServices({
                operation: method,
                async: false,  //if you set this to true, you may get faster performance, but your order may not be accurate.
                listName: list,
                CAMLViewFields: fieldsToRead,
                  CAMLQuery: query,
                      //this basically means "do the following code when the call is complete"
                    completefunc: function (xData, Status) {
                        //this code iterates through every row of data returned from the web service call
                        $(xData.responseXML).SPFilterNode("z:row").each(function() {
                            //here is where we are reading the field values and putting them in JavaScript variables
                           
                         
                            //get the title field (ID)
                            var empNumber = ($(this).attr("ows_Employee"));
                            //get eployee first name
                            var empFname = ($(this).attr("ows_FirstName"));
                            //get emplyee last name
                            var empLname = ($(this).attr("ows_LastName"));

                            var empSup = ($(this).attr("ows_Supervisor"));

                            var empPay = ($(this).attr("ows_Pay"));

                            var empLoc = ($(this).attr("ows_Location"));

var firstName = $().SPServices.SPGetCurrentUser({
             fieldName: "FirstName"              
         });
       
       
         if(empFname == firstName){

                      $("input.needsName").val(firstName);
                      $("input.needsEmpnum").val(empNumber);
                      $("input.needsSup").val(empSup);
                      $("input.needsLoc").val(empLoc);
                  $("input.needsPay").val(empPay);
}
else
{
//alert("Not a match");
}
                     
                        });                
                    }
        });
 
});
cbridgesazAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rajendra ShekhawatSolution ArchitectCommented:
Hi,

Which version of SharePoint you are using ?

If using SP 2013, you can look into REST API and Filter operators to get corresponding data from server itself.

Cheers,
Raj
cbridgesazAuthor Commented:
I actually solved this issue by adjusting the query filter to lookup and compare user name in list  with logged in user, this created a smaller range for the .SPServices call to sort out, speeding up the comparison extremely.

var firstName = $().SPServices.SPGetCurrentUser({
             fieldName: "FirstName"              
         });
        //alert(firstName);
            var query = "<Query>" +
                        "<Where>" +
                            "<Eq>" +
                                "<FieldRef Name='FirstName'/><Value Type='Text'>" + firstName + "</Value>" +
                            "</Eq>" +
                        "</Where>" +
                        "<OrderBy>" +
                            "<FieldRef Name='ID'/>" +
                        "</OrderBy>" +
                    "</Query>";

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cbridgesazAuthor Commented:
Adjusting the filter gave a smaller query range which sped up the search.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.