Domanda

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.

È stato utile?

Soluzione

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);
  }
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top