This project has moved. For the latest updates, please go here.

SPServices Issue with SP2007

Sep 3, 2013 at 8:53 PM
I'm trying to get the current user and it doesn't appear to be working. Here's my code...
curUser = $().SPServices.SPGetCurrentUser({
   fieldNames: ['ID','Name','Title','EMail'],
   debug: false
Object doesn't support property or method 'replace' at line 21 character 47248

Is one of my properties that I'm retrieving coming back empty or something?
Sep 3, 2013 at 11:28 PM
What versions of SPServices and jQuery are you using?


Sent from Mobile
Sep 4, 2013 at 7:28 AM
Are you loading spservices after loading jQuery?

Sep 4, 2013 at 1:46 PM
Using jQuery 1.8.3 and SPServices 2013.01. I'm loading jQuery and all plugins before I load SPServices.
Sep 4, 2013 at 2:15 PM

Have you tried retrieving only one value? I'm wondering if I have some sort of bug in getting multiple values, e.g.,

Sep 4, 2013 at 2:54 PM

I was thinking the same thing. It might not be taking nulls into account when building the array. I will retrieve one at a time and let you know.

Sep 4, 2013 at 5:14 PM
Weird, only ID is returning. Name, Title, and EMail are all blank.
Sep 4, 2013 at 5:16 PM
Have you checked the userdisp.aspx page for the user? Only values which are present on that page will be returned.

Sep 4, 2013 at 6:02 PM
Name, Work e-mail, Account, SIP Address, First name, Last name, Work phone, and User name are all available.
Sep 4, 2013 at 6:11 PM
Strange, the admin account works but my personal account doesn't. They appear to have the same fields populated, except the admin account only has First Name populated.
Sep 4, 2013 at 6:18 PM
I thin k the line where you're getting the error is this one:

thisField = (typeof thisField !== "undefined") ? thisField.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '') : null;

That's line 2345 in 2013.01 (not minified). If you could step through that function and let me know what you see going wrong, that would be really helpful.

Sep 4, 2013 at 6:35 PM
I'm getting a "Object doesn't support property or method 'replace'" error on this line...

if(aG.fieldNames[0]!=="ID"){aC=(typeof aC!=="undefined")?aC.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g,"") : null}
Sep 4, 2013 at 6:39 PM
That's the same line as I show above, but in the minified version. If you could put a breakpoint there and figure out what the value of aC is (or thisField in the non-minified version), we might be able to figure out what's happening.

The other thing that would help is if you can identify which field is causing the problem.

Sep 4, 2013 at 6:44 PM
The value of aC is 4808, which is the ID and the 'typeof aC' is 'number'. That appears to be what is throwing the error.
Sep 4, 2013 at 7:03 PM
Hmm. The line that does the replacement is wrapped like so:
            if(opt.fieldNames[i] !== "ID") {
                thisField = (typeof thisField !== "undefined") ? thisField.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '') : null;
So the replace shouldn't even happen for the ID. That's exactly why I have that test there.

Sep 4, 2013 at 7:32 PM
I'm going to try it with the non-minified version so I can debug it easier
Sep 5, 2013 at 2:16 PM
Ok, it's the Name field that is throwing the error and thisField is 4808. Finally got that figured out.
Sep 5, 2013 at 2:25 PM
When I pull each field one at a time, ID is the only field it is returning.
Sep 5, 2013 at 2:36 PM
Ok, I bet it's related to this issue, then:

There are two syntax options, one with fieldName and one with fieldNames. Note the "s" in the latter one. I added that second syntax in a later version than the first and wanted to maintain compatibility. One workaround might be to make 4 separate calls with fieldname, but obviously that will be inefficient.

It looks like the Name column is getting assigned the ID value. I'm still not sure why that is happening, but since it is a numeric object, the replace is failing. I'd like to understand what the issue is so that I can fix the bug. If you're comfortable debugging and can figure it out, everyone can benefit!

What if you do this?

curUser = $().SPServices.SPGetCurrentUser({
   fieldNames: ['Name','Title','EMail'],
   debug: false
i.e., omitting the ID?

Sep 5, 2013 at 2:43 PM
No errors this time, but still nothing being returned for those fields.
Sep 5, 2013 at 2:58 PM
Erg. And the values are definitely in the userdisp.aspx page?

I wonder if there's something unique about your environment. How custom is the branding, etc.? Are there any customizations on the userdisp.aspx page itself?

If you can send me the View Source for the userdisp.aspx page, that might help. marc dot anderson @ sympraxisconsulting dot com.

Sep 5, 2013 at 3:01 PM
Sep 5, 2013 at 3:19 PM
You've got a lot of custom stuff in that page, but it looks like the main user display area is pretty normal. The markup in my userdisp.aspx page looks the same as what's in yours, at least for Name.

When I run exactly your code, it works on my end, too, with or without the ID. I'm running out of ideas. More stepping through the script?

Sep 5, 2013 at 4:37 PM
This WAS working at one point and I don't know what changed. It is working fine when I log in with the admin account but not when I use my personal account. Does that help?
Sep 5, 2013 at 4:51 PM
Maybe. When you are logged in as your personal account, can you reach the page /_layouts/userdisp.aspx?Force=True and see the right content? It could simply be a permissions thing.

The way the function works is that it loads the page /_layouts/userdisp.aspx?Force=True and then basically screen scrapes the values out of the DOM. To do this, it looks for the appropriate fields by searching for the FieldInternalName="column name" text in the comment above the actual field data.

Sep 5, 2013 at 4:53 PM
Yup, I can see everything just fine on that page whether I am logged in as myself or admin. :-/
Sep 5, 2013 at 5:45 PM
Got it! I had to specify the webURL in order for it to work for my personal account. Now it works for both!
Sep 5, 2013 at 6:35 PM
I'm not sure why that works. Were you trying to get the info from a different Site Collection?

Sep 5, 2013 at 6:39 PM
I was just on a sub-site within the root site collection. I thought it was weird too.
Sep 5, 2013 at 6:52 PM
Well, if it works, it works. You should be able to access userdisp.aspx identically from http://server/_layouts or http://server/subsite/_layouts.