Understanding Deferred Objects and SPServices

Aug 14, 2015 at 7:31 PM
Edited Aug 14, 2015 at 7: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 }) ;
  curUser.done(function(){

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

  }) ;
}
Aug 14, 2015 at 8: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 10: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.

Paul
-- sent from mobile

Aug 17, 2015 at 3: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.
Coordinator
Aug 18, 2015 at 2: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.

M.