$().SPServices() is not a function.

Home Forums Classic DFFS $().SPServices() is not a function.

Tagged: 

Viewing 10 reply threads
  • Author
    Posts
    • #37828

      Hello,
      I am using DFFS for a SharePoint Online list. I have CustomJS that pulls data from another SharePoint List(Staff Master List). I am getting $().SPServices is not a function .

      I have added the JQuery Reference on Site Assets & also referenced them on the text area above the CustomJS.
      Seems like JQuery is not getting loaded, but not sure how to resolve.

      function setDemoValues()
      {
          
          var PreferredName = "";
          $.each(spjs.utility.getFieldValue({"fin":"Employee_x0020_Name","key":"loginName"}),function(i,login){
          var userProfile = spjs.utility.userProfile(login);
          PreferredName = userProfile.PreferredName;
          setFieldValue('Title', PreferredName);
          });
          
          var query = "<Query><Where><Eq><FieldRef Name='Name' /><Value Type='User'>" +PreferredName + "</Value></Eq></Where></Query>";
          var camlViewFields = "<ViewFields><FieldRef Name='Reports_x0020_To'/><FieldRef Name='Department'/><FieldRef Name='Position'/><FieldRef Name='Job_x0020_Title'/></ViewFields>";
          
          $().SPServices({
              operation: "GetListItems",
              async: false,
              webURL: "http://xxxx/yyyyyyyy", 
              listName: "Staff Master List", 
              CAMLViewFields: camlViewFields, 
              CAMLQuery:query, 
              completefunc: function(xData, Status) 
              {
          		$(xData.responseXML).SPFilterNode("z:row").each(function() {
          		    
          		    if ($(this).attr("ows_Reports_x0020_To"))
          		    {
          		        TeamLeadr_str = $(this).attr("ows_Reports_x0020_To").split(';#')[1];
          		        setFieldValue('Reports_x0020_To',TeamLeadr_str);
          		    }
          		    if ($(this).attr("ows_Department"))
          		    {
          		        setFieldValue('Department', $(this).attr("ows_Department"));
          		    }
          		    if ($(this).attr("ows_Position"))
          		    {
          		        setFieldValue('Position', $(this).attr("ows_Position"));
          		    }
          		    if ($(this).attr("ows_Job_x0020_Title"))
          		    {
          		        setFieldValue('Position_x0020_Level', $(this).attr("ows_Job_x0020_Title"));
          		    } });
               }
            });
      }
      
    • #37829
      Alexander Bautz
      Keymaster

        Hi,
        SPServices is not part of DFFS. If you want to use it you must load it in the textarea above Custom JS.

        You don’t need to use it either as DFFS has built in support for getting list items – see this thread for example code: https://spjsblog.com/forums/topic/query-update-delete-an-item-in-javascript/

        Alexander

      • #37830
        Alexander Bautz
        Keymaster

          I forgot to mention that jQuery is automatically loaded with DFFS so you must not load it again – that can cause problems.

          Alexander

          • #37835

            Please correct me if I’m wrong. Now I can remove the JQuery Reference, is what you mean ?

          • #37836
            Alexander Bautz
            Keymaster

              I referred to jQuery as the jQuery JavaScript library and not jQuery.SPServices so your setup should be OK.

              I guess that the $ namespace (alias for jQuery) used in the SPServices library for some reason is not populated when jQuery is loaded. I have seen that SharePoint or other third party code uses the same namespace.

              You can try adding something like this in the top of your Custom JS to fix it:
              $ = jQuery;
              I still recommend using the built in spjs.utility functionality linked in my previous answer instead of SPServices.

              Alexander

            • #37894

              I have added $ = jQuery; on to of Custom JS. Still facing the same issue as below.
              Also I have tried using QueryItems from SPJS.Utility, then I am getting errors at the View Fields, as my requirement is to retrieve many columns of a different SharePoint List. Shall Share the error soon now,

          • #37898
            Alexander Bautz
            Keymaster

              If you can show me the code you have written using spjs.utility I’ll help you get the syntax correct.

              Alexander

            • #37904

              Hi Alex,
              Sorry for the delayed reply. I have tried using the SPJS.Utility method as suggested by you and getting the below error at ViewFields. When I try to read the items from a sample list (DFFS_TestList) the same code works like a charm. Is there any item limit for CamlViewfields.

              Below is the code :
              var query = “<Query><Where><Eq><FieldRef Name=’Name’ /><Value Type=’User’>” +PreferredName + “</Value></Eq></Where></Query>”;
              var camlViewFields = “<ViewFields><FieldRef Name=’Reports_x0020_To’/><FieldRef Name=’Department’/><FieldRef Name=’Position’/><FieldRef Name=’Job_x0020_Title’/><FieldRef Name=’Hire_x0020_Date’/><FieldRef Name=’Perm_x0020_Date’/><FieldRef Name=’Status’/><FieldRef Name=’ADP_x0020_File_x0020__x0023_’/><FieldRef Name=’Location’/><FieldRef Name=’Company’/><FieldRef Name=’ADP_x0020_File_x0020__x0023_’/><FieldRef Name=’Sprout_x0020_Employee_x0020_ID’/></ViewFields>”;
              var TeamLeadr_str = “”;
              debugger;
              spjs.utility.queryItems({
              “listName”: “Staff Master List”, // List display name or GUID
              “listBaseUrl”:”http://team/TraditionalQA&#8221;,
              “query”: query,
              “viewFields”: camlViewFields
              });

              Attachments:
              • #37908
                Alexander Bautz
                Keymaster

                  This function is supposed to be used like this:

                  
                  var PreferredName = "your_variable_input";
                  var query = "<Where><Eq><FieldRef Name='Name' /><Value Type='User'>" + PreferredName + "</Value></Eq></Where>";
                  var camlViewFields = ["Reports_x0020_To", "Department", "Position", "Job_x0020_Title", "Hire_x0020_Date", "Perm_x0020_Date", "Status", "ADP_x0020_File_x0020__x0023_", "Location", "Company", "ADP_x0020_File_x0020__x0023_", "Sprout_x0020_Employee_x0020_ID"];
                  var TeamLeadr_str = "";
                  var res = spjs.utility.queryItems({
                      "listName": "Staff Master List", // List display name or GUID
                      "listBaseUrl": "/sites/site_name",
                      "query": query,
                      "viewFields": camlViewFields
                  });
                  if(res.count > 0){
                      console.log(res.items);
                  }else{
                      console.log("no items found");
                  }
                  
                  • This reply was modified 4 months, 3 weeks ago by Alexander Bautz. Reason: Fixed code snippet
                  • This reply was modified 4 months, 2 weeks ago by Alexander Bautz. Reason: Fixed code snippet
              • #37919

                Hi Again,
                While using the above code, on the TestList, I am getting the below error. Where get list items is success, but the control executes the error block.

                Attachments:
                • #37922
                  Alexander Bautz
                  Keymaster

                    I have fixed the error in the code (I mixed up the format of the returned data).

                    Alexander

                • #37923

                  Thanks , this worked. Just a last check, When the Query list resides on SharePoint 2016 On-Prem, this solution fails, is that a limitation? For any SharePoint Online list, I am able to get the values.

                • #37924
                  Alexander Bautz
                  Keymaster

                    Not sure, what kind of error are you getting?

                    Alexander

                    • #37925

                      No specific error, but just that the res.items is 0, whereas the res.items has a count with SharePoint Online Lists.

                    • #37926

                      Also, the Query doesn’t seems to work, as in the res.items.Count is getting me the entire list item count, instead it should be 1.

                  • #37927

                    Here’s the screenshot

                    Attachments:
                  • #37935
                    Alexander Bautz
                    Keymaster

                      When using spjs.utility.queryItems you are only supposed to use <Where>…</Where> in the query part – not <Query><Where>…</Where></Query>

                      Alexander

                    • #37938

                      Thanks, Worked.!!!

                      • #37946
                        Alexander Bautz
                        Keymaster

                          Thanks for the feedback – I’m glad you got it up and running.

                          Alexander

                    Viewing 10 reply threads
                    • You must be logged in to reply to this topic.