SPGetCurrentUser error when picture is blank

Nov 16, 2011 at 3:52 PM

When using the following code:

  var usrPicLink = $().SPServices.SPGetCurrentUser({
 fieldName: "Picture",
 debug: true
   });

and the picture field is null, I get the following error:

SCRIPT5007: Unable to get value of the property 'replace': object is null or undefined

jquery.spservices-0.6.2.min.js, line 19 character 42667

I got this in both IE and FF, using the 0.6.2 and jquery: 1.6.2

return t.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g,"")}

Can you confirm this to be a bug or if I am missing something.

Thanks so much and I love this SPservices!!!

Nov 17, 2011 at 2:57 AM

i don't think thats a bug.. it means that the field has no value. You see those errors accessing fields in SP when its totally blank. I just used this the other day and I think this is what i did.

var usrPicLink = null;

try

{
 usrPicLink = $().SPServices.SPGetCurrentUser({
 fieldName: "Picture",
 debug: false
   });

}

catch(err)

{

usrPicLink = "/somedefaultimage.jpg";

}

Nov 17, 2011 at 1:57 PM

that is perfect!  Bug or not...thanks for the solution...works great!

Coordinator
Nov 17, 2011 at 6:59 PM

Regardless of the workaround, that's my bug. I'll get a fix into the upcoming release so that SPServices doesn't throw an error, but returns a null.

M.

Coordinator
Nov 17, 2011 at 7:00 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 18, 2013 at 9:49 PM
I'm getting the same error:

SCRIPT5007: Unable to get property 'replace' of undefined or null reference
jquery.SPServices-0.7.2.min.js, line 19 character 46073