Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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) {
                    alert("User in a group");
                }
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.

share|improve this question
    
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? –  PirateEric Jan 29 '13 at 16:39
add comment

3 Answers 3

Ì had this issue when loading jQuery on the page and later adding jQuery to the master page for the site.

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.

share|improve this answer
add comment
up vote 0 down vote accepted

I just kept the Content editor webpart at bottom in the webpart zone. that's it. it is working fine now.

share|improve this answer
add comment

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>

Here I perform a somewhat similar task: http://sharepointnadeem.blogspot.in/2011/09/hide-sharepoint-list-field-based-on.html

share|improve this answer
    
This is not correct. This example assumes that his JavaScript assets are in the root site of the web application, which is not the case given the example paths in the original post. There is nothing wrong with the way Srikanth has loaded his JavaScript. –  webdes03 Jan 29 '13 at 13:47
    
I was just showing an example based on his comment: "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." –  Nadeem Yousuf Jan 29 '13 at 13:52
    
@webdes03 Do you have any other alternate solution to find out user group? –  Srikanth Jan 29 '13 at 14:02
    
@Srikanth, Since you are in SP 2010, you can also try ECMA script Client Object model. –  Nadeem Yousuf Jan 29 '13 at 14:09
    
@NadeemYousuf Ohh. I tried the solution that you provided in a link but still getting the error (I did not reference as you did, I keep my original as mentioned in question). –  Srikanth Jan 29 '13 at 14:12
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.