# 'SPServices' is null or not an object

I need to find out if logged in user belongs to a specific sharepoint group (2010). I am using below code to get it. but getting javascript error as 'SPServices is null or not an object'.

    <script src="/sites/XXX/XXXX/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="/sites/XXX/XXXX/jquery.SPServices-0.7.1a.min.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function () {$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(), async: false, completefunc: function (xData, Status) { if ($(xData.responseXML).find("Group[Name='Site Admin']").length == 1) {
}
else{
alert ("User is not in group");

}
}

});

});</script>


So many are saying the error occurs if jquery files not referenced properly. I stored the files in a doc library and referencing it in javascript.

• do I have to add _spBodyOnLoadFunctionNames.push(); also at the end? – Srikanth Jan 29 '13 at 12:56
• Try absolutely referencing them to ensure they are loading properly. What is loading this script? is it a js file you have stored and are referencing in a CEWP or is this baked into a page layout/master page? – Eric Alexander Jan 29 '13 at 16:39

It can be useful to use the web debugger in Chrome to view exactly which scripts are being loaded.

1. Press 'F12' to launch the tool
2. Open the 'Resources' Tab
3. Expand the frames then the page folder
4. The scripts folder will show all the currently loaded scripts.

Check here to see if you have any duplication.

• And what if you have to add it to both? I ran into where I was loading SPServices on the master, but in the context of an HTML Form Editor webpart, it was not being recognized. Tried adding the reference to SPServices even there but still got the same error as the OP. Telling someone to "check their script loading" doesn't tell them how to resolve where/how to load them. – vapcguy Mar 10 '16 at 22:28
• The OP was unsure if the library was being referenced properly, the above steps will allow you to confirm that your reference is working and the library is loading. – liamog Mar 11 '16 at 13:11
• And I'm telling you that, no, it doesn't, because I tried it. It found my master page reference to SPServices, but I still had an error like it wasn't loading. The master page referred to a different, known working one than I ultimately referenced in my webpart. It wasn't until I referenced another location (and replaced that file with a known good one) within my webpart that it started working. So tips like this don't always work - they can find the resources just fine, they don't tell you they're actually being used in the context of the code that is being run - ESPECIALLY within webparts. – vapcguy Mar 30 '16 at 14:17

Had a similar issue. So what I found was I could add the reference inside my HTML Form Editor web part - I did this like this:

<script src="../SiteAssets/js/jquery.SPServices-0.7.2.min.js" type="text/javascript"></script>


but it would give me the error like the OP found at just this line of code:

var userName = \$().SPServices.SPGetCurrentUser();


as if it was not loading SPServices. There was another SPServices file (same version, also minified) on another site where it was working correctly, so I replaced my version with that one, and it started working after I refreshed my page. Perhaps it was corrupted or something had happened when I downloaded my original SPServices file, or because I don't remember where I downloaded it from, if it was some GitHub or other similar place I go to occasionally, it could have been modified in a way that made it unserviceable. Guess that's a lesson to me that I need to be sure of where my files are coming from and that I get stable versions...

There are a few later versions than this that I don't have time to try, but this has the stable version of jquery.SPServices-0.7.2.min.js that I can vouch works: https://spservices.codeplex.com/releases/view/81401

Here is an example that shows how to reference the js files present in Document Library.

<script type="text/javascript" src="/Shared%20Documents/JS/jquery.min.js"></script>
<script type="text/javascript" language="javascript" src="/Shared%20Documents/JS/jquery.SPServices-0.6.2.min.js"></script>