This project has moved and is read-only. For the latest updates, please go here.

Understanding Deferred Objects and SPServices

Aug 14, 2015 at 8:31 PM
Edited Aug 14, 2015 at 8:32 PM
So does $().SPServices.GetGurrentUser({}); return a deferred object? If so, I can't seem to use .done().

I'm trying/wanting to do something like this:

Project.GetUserInfo = function(){
  var curUser = $().SPServices.SPGetCurrentUser({ // options }) ;

       return jsnUser = {
             user  : curUser,
             userAgt : navigator.userAgent ;

  }) ;
Aug 14, 2015 at 9:07 PM
MyProject.Users.GetCurrentUser = function () {
var userPromise = $.Deferred();

userPromise = $().SPServices.SPGetCurrentUser({
    fieldNames: ['Name', 'Title', 'Email', 'UserName', 'FirstName', 'LastName'],
    debug: false
}); // end SPGetCurrentUser

return userPromise.promise(); // error: object doesn't support property or method 'promise'

Aug 14, 2015 at 11:40 PM
I don't believe (according to the documentation) that this method returns a promise... It seems to return the value(s) you asked for - so your case, it should be returning an object with the properties you requested.
The docs have some examples - try those. If that still does not work for you, set a break point and inspect the value returned.

-- sent from mobile

Aug 17, 2015 at 4:10 PM
Thanks for your reply.

I agree. I spet hours over the weekend setting breakpoints and examining the returned object. Then I dug a bit deeper and realized this utility is merely querying the pages controls for the data.

So yes...

This doesn't return a DO.

Again, thanks for taking the time to reply to my question. I really appreciate it.
Aug 18, 2015 at 3:03 AM
This is a function I wrote very early in SPServices, before I even knew what promises were. In order to avoid a breaking change, I've left is as a synchronous call.