gitbrent/SpRestLib

not able to pass site url for "User Methods"

YakQin opened this issue · 5 comments

Hello,
I looked into the source code too but I did not find a way to pass the site url for "User Methods". I usually complete the application (js, css, html) locally and then when everything is fine I upload the package to sharepoint folder then users can access the .aspx pages (changed extension from html to aspx) So I always use the complete sharepoint site url.

So if you can set global var for the baseUrl for all functions or at least for the User Methods then it will be much more useful.

Currently I use the original Ajax call for all the projects

function currentLogin() {
     $.ajax({
         url: "xxxx/teams/apmt/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=DisplayName,Email",
         async: false,
         type: 'get',
         headers: {
             "Accept": "application/json;odata=verbose"
         },
         cache: false,
         //dataType: 'json',
         success: function(spJsonData) {
             //get user name
             var pageDisplayName;
             var displayName = spJsonData.d.DisplayName
             var isLongerDisplayName = displayName.search(/[(]/)
             if (isLongerDisplayName != -1) {
                 var bracketStart = displayName.indexOf("(")
                 pageDisplayName = displayName.substring(0, bracketStart)
             } else(pageDisplayName = spJsonData.d.DisplayName)
             var loginMsg = "Welcome " + pageDisplayName
             $("#login-name").html(loginMsg)
             //get user mail id
             $("#userMail").html(spJsonData.d.Email)
             var picURL = "url(https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email=" + spJsonData.d.Email + ")"
             $("#login-image").css("background-image", picURL)
         },
         error: function() {
             $("#login-name").html("Welcome ,[...]")
         }
     });
 }

Hi @YakQin,

I thought all users existed on the server, so regardless of URL, you'd get the same info...?

Ex:
screen shot 2018-01-01 at 16 26 54

Hello,

I first create everything locally (on by desktop), once I finished the app, I then upload all files to a sharepoint folder. Before I upload the files, I have to use the sharepoint url to interact with sharepoint. So my request is whether we can add the option to give the full sharepoint url then we can use the library locally but not in sharepoint environment.

sp

Oh yeah, that makes perfect sense. :-)

I'll get the baseUrl option added. Thanks for the suggestion.

Hi @YakQin

The user() method now accepts baseUrl just like list() does (either a complete or relative url):

sprLib.user({ baseUrl:'/sites/dev/sandbox' }).info()
.then(objUser => console.log(objUser))

@gitbrent
thanks a lot. it worked for me! now i can fully count on this lib

user