SPServices SPGetCurrentUser does not retrieve any info

Aug 21, 2013 at 8:21 AM
I have been having some difficulty getting this to work.

We are currently on Office 365.
SPServices on the whole works - we have a production system using some commands.

However, I have been having some trouble with SPGetCurrentUser working.
At first I tried using version 0.7.2 together with jquery 1.8.3 in a different site collection but discovered that it won't work since I need to be able to see the current site plus '_layout/userdisp.aspx'

So I switched to using SPServices 2013.01 but it still didn't work. Here is my code snippet:
//Get the user loginName
var currentuserval = $().SPServices.SPGetCurrentUser({
    webURL: 'https://mydomain.sharepoint.com',
    fieldName: 'Title',
    debug: true
});
alert(currentuserval);
After that didn't work, I tried something simpler:
alert($().SPServices.SPGetCurrentSite());
alert($().SPServices.SPGetCurrentUser({webURL:'https://mydomain.sharepoint.com', fieldName:'Title'}));
I still get a blank for the result. I tried to use SPGetCurrentUser on my root site but still have the same blank issue.
Aug 21, 2013 at 10:02 AM
Some further info I got while using IE8's debug function for the first code snippet:

thisWeb was having the value of "https://mydomain.sharepoint.com"

thisUserDisp.status = 200
thisUserDisp.statustext = "OK"
thisUserDisp.readyState = 4
thisUserDisp.responseText = "" (This was literally a blank field)

thisField = ""

It's probably because the responseText is showing blank. But I could go to https://mydomain.sharepoint.com/_layouts/userdisp.aspx?Force=true directly and see all the details...
Aug 21, 2013 at 1:14 PM
This is a know bug. It has to do with the fact that the web is the root site. The link to the bug is below, which I think the user also mentions how to address it. Maybe you do the change on your copy of SPServices to get around it until Marc includes the fix in the next version.

http://spservices.codeplex.com/workitem/10155

_____
Paul

Sent from mobile device.

Aug 21, 2013 at 3:47 PM
Thanks for your quick reply Paul.

But that can't be right. The known bug is only because of running the command in the root web ie https://mydomain.sharepoint.com
In my case, I'm actually running it on a sub-site in a site collection ie (from SPGetCurrentSite, I got /Site1/subsiteA/)

I have tried going directly to the following:
https://mydomain.sharepoint.com/_layouts/userdisp.aspx?Force=true
https://mydomain.sharepoint.com/Site1/subsiteA/_layouts/userdisp.aspx?Force=true

But only the first link works. So my arguments of SPGetCurrentUser({webURL: 'https://mydomain.sharepoint.com', fieldName:'Title'}) should be correct in theory.

I will try the workaround to see if it works.


Christopher
Aug 21, 2013 at 8:07 PM
I see what you mean now... and since you are explicitly defining webURL it would also not encounter the bug I pointed out...

This is in fact weird.. It should work... I just ran your code (in your first post) on Office365 SP2010 and it worked fine (even with a webURL of 'https://mydomain.sharepoint.com' as you had above - which is definitely weird... I may download 0.7.2 source to look at it. I also ran it on SP2013 and again, it was successful.

If the page is accessible via the web, which you say the first URL is, then you should be able to get the values out... If you have Firefox with Firebug plugin, can you open the console and then refresh the page... Look at the network traffic that is sent/received for anything unusual. (also: you are not going across domains, correct?)

Paul.
Aug 21, 2013 at 8:14 PM
I should have waited to post my last message..
I just looked at the source for 0.7.2 and its version of SPGetCurrentUser does not support setting webURL as an input param - thus why I was able to successfully pull info. out with an invalid webURL param value. Looks like it always uses "current site" which in your case, is bad (since you don't seem to have a valid userdisp.aspx page)

I think you have two options:
  1. Upgrade to a newer version of SPServices (the 2013.01 seems to support a webURL param)... or
  2. Determine why your subsite does not have a valid /_layouts/userdisp.aspx page...
Paul.
Aug 22, 2013 at 2:58 AM
Dear Paul,

Thanks for your help with troubleshooting this.

I have re-tried the 2 URLs straight from the browser:
https://mydomain.sharepoint.com/_layouts/userdisp.aspx?Force=true
https://mydomain.sharepoint.com/Site1/subsiteA/_layouts/userdisp.aspx?Force=true

They both work now! It must have been a typo earlier.
However, it didn't solve my problem.
I have tried the following as well:
Used the 2013.01 version and defined the webURL but still no luck
Tweaked the 0.7.2 version (the SPGetCurrentSite shows the complete URL, not the relative one) and removed the time bit so that it'll be exactly the same as if I entered the URL on the browser.
Unfortunately, all show that the responseText is blank, which I think means that the command is retrieving a blank page.

Kind of stuck on what to do next...
Aug 22, 2013 at 3:55 AM
Any chance you have Firefox running with firebug plugin. If so, take a look at the network traffic and check what URL is being used and if anything is coming back.

_____
Paul

Sent from mobile device.
Aug 22, 2013 at 7:18 AM
Dear Paul,

I just installed Firefox and the Firebug plugin. My current is IE8 (I know it's old but some other corporate applications prevent use of IE9 and above).
I fired up the test page on Firefox and the SPGetCurrentUser WORKS PERFECTLY!!!

Well, it looks like I've nailed down to an IE issue. Now to find out how to solve it (Company policy - We use/support IE only)...
Aug 22, 2013 at 8:41 AM
Image

This is the Net result from Firefox. I took this snapshot as the alert for the SPGetCurrentUser came up.
Aug 22, 2013 at 8:43 AM
I did a google search and this seemed to be a similar issue although my problem is with IE8 and not IE9

https://spservices.codeplex.com/discussions/362280
Aug 22, 2013 at 9:54 AM
So far I think the issue is not so much that SPGetCurrentUser is not working, but that it is returning a blank result. And this is happening for IE8 only
I can't test this with Chrome because I cannot authenticate and load my Office 365 page on Chrome, Firefox works perfectly fine.
Aug 22, 2013 at 11:41 AM
So at least we're narrowing the problem down. It works in FF - that's good - the utility seems to do its job. Now we can focus on IE. As soon as I have a moment, I'm going to fire up my IE8 VM and give it a try. IE makes it harder to debug these types if issues because it does not have a network traffic analyzer. You have to use fiddler.

Tell me again: what are the jQuery, SPServices, SharePoint versions your working with?

_____
Paul

Sent from mobile device.
Aug 22, 2013 at 12:13 PM
For jquery I'm using 1.8.3
For SPServices I'm using 0.7.2
SharePoint is a little dodgy, as I've mentioned before, we are on Office 365 and they recently upgraded our backend to 2013 but I think the core is still 2010.

In case, it didn't get through earlier, thanks so much for the help in troubleshooting.
Aug 30, 2013 at 6:46 AM
Dear Paul,

Were you able to find out more info?

Christopher
Coordinator
Aug 30, 2013 at 7:30 PM
You shouldn't need to specify the WebURL, and in most cases you wouldn't want to anyway. The userdisp.aspx page shows values for the user in the current Site Collection.

I just tried the function on my Office365 instance (same as you; the back end is 2013, but I see 2010) and it works for me.

M.
Aug 31, 2013 at 2:20 PM
Christopher,
Sorry for the delay. Like Marc, I tried with the exact versions that you have and it works. You may need to get into the code and insert breakpoint the analyze what's going on.

Note: I'm not sure that this is an issue with SPServices though. You indicated the response is blank (not sure how you are figuring that out. Using the debugger?). Try getting the page just using jquery and see if it is able to retrieve it. (I think it will based on the screen capture above).
_____
Paul

Sent from mobile device.
Mar 24, 2014 at 2:31 AM
Hi Guys, did you find any answer?

I had a similar experience, I was having the same problem, so I checked the source code and I found the call to the web services thorugh the page userdisp.aspx

url: thisWeb + "/_layouts/userdisp.aspx?Force=True&

was not working at the the root site web, so I had to use the param WebURL to pass the absolute path

something like this

var currentAbsoluteUrl = window.location.protocol + "//" + window.location.host
    var currentUserName= $().SPServices.SPGetCurrentUser({
        webURL:currentAbsoluteUrl,
        fieldName: "Name",
        debug: false
    });

It worked!, hope this helps someone else

cheers
Coordinator
Mar 24, 2014 at 1:08 PM
First suggestion would be to use the latest release, which is 2014.01. If it's not working in that release, please let me know.

M.
Feb 21, 2015 at 5:40 PM
Saved my life!, thank you LuisNJuarez