Home › Forums › Classic DFFS › $().SPServices() is not a function.
Tagged: DFFS
- This topic has 19 replies, 2 voices, and was last updated 4 months, 2 weeks ago by Alexander Bautz.
-
AuthorPosts
-
-
July 25, 2024 at 13:12 #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")); } }); } }); }
-
July 25, 2024 at 18:22 #37829
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
-
July 26, 2024 at 14:18 #37832
Hi Alexandar,
I have already added the JQuery Library to my Site Assets and referenced in the text area above the CustomJS. Please find image.Attachments:
-
-
July 25, 2024 at 18:24 #37830
I forgot to mention that jQuery is automatically loaded with DFFS so you must not load it again – that can cause problems.
Alexander
-
July 26, 2024 at 14:20 #37835
Please correct me if I’m wrong. Now I can remove the JQuery Reference, is what you mean ?
-
July 26, 2024 at 14:43 #37836
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
-
July 29, 2024 at 12:58 #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,Attachments:
-
-
July 29, 2024 at 15:23 #37898
If you can show me the code you have written using spjs.utility I’ll help you get the syntax correct.
Alexander
-
August 1, 2024 at 12:53 #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”,
“query”: query,
“viewFields”: camlViewFields
});Attachments:
-
August 1, 2024 at 13:42 #37908
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
-
August 6, 2024 at 04:19 #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:
-
August 6, 2024 at 12:42 #37922
I have fixed the error in the code (I mixed up the format of the returned data).
Alexander
-
August 6, 2024 at 14:24 #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.
-
August 6, 2024 at 14:50 #37924
Not sure, what kind of error are you getting?
Alexander
-
August 7, 2024 at 09:03 #37925
No specific error, but just that the res.items is 0, whereas the res.items has a count with SharePoint Online Lists.
-
August 7, 2024 at 11:36 #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.
-
-
August 7, 2024 at 11:52 #37927
Here’s the screenshot
Attachments:
-
August 7, 2024 at 15:12 #37935
When using spjs.utility.queryItems you are only supposed to use <Where>…</Where> in the query part – not <Query><Where>…</Where></Query>
Alexander
-
August 8, 2024 at 09:19 #37938
Thanks, Worked.!!!
-
August 8, 2024 at 19:25 #37946
Thanks for the feedback – I’m glad you got it up and running.
Alexander
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.