0

I am using SPServices to get current user like this:

var user = $().SPServices.SPGetCurrentUser();

This works fine in the main site, but when I use the same line of code in subsite, I get:

Uncaught TypeError: Cannot read property 'SPGetCurrentUser' of undefined

I couldn't find too much information about it, but I assume, I can only use this method on the main site?

If so, what alternatives (without asynchronous call) would you suggest to get current user on subsite level? I need SPUser object as a return value.

  • $().SPServices script file is loaded in your sub site? Check it? – Atish Dipongkor - MVP May 31 '16 at 10:50
  • @AtishDipongkor Yes, all the scripts are loaded as in main page :) – Gintas K May 31 '16 at 10:56
  • Sometimes JS problems occur due to not activating of Publishing feature. So can you check that 'SharePoint Server Publishing Infrastructure' site collection feature & 'SharePoint Server Publishing' site feature is activated or not. – Ronak Patel May 31 '16 at 11:13
  • @RonakPatel , that's a good shot. The page publishing feature was off on subsite, just activated it, the issue still persists though :( – Gintas K May 31 '16 at 11:32
2

It will not work as it is already mentioned in Codeplex comments & there is no solution mentioned over there as well.

You need to make standard ajax call but it will give you XML with having all user's information in it using below code (As you required SPUser so i cleared the output).

$.ajax({
  url: "/_api/lists/getbytitle('User Information List')/items?$filter=Title eq '" + employeeName + "'&$select=Department,JobTitle",
  type: "GET",
  async: false,
  success: function (xml) {
    department = $(xml).find('d\\:Department, Department').text();
    jobTitle = $(xml).find('d\\:JobTitle, JobTitle').text();
  },
  error: function (a, b, c) {
    alert(c);
  }
});
  • Ohh.. you used SharePoint 2013 CSOM. that is also fine. :) – Hardik May 31 '16 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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