I am trying to get the URL of the logged in user's Personal site from another site collection. I am working on SharePoint 2013 online and using ECMA.
Use the below code
function getPersonalUrl() {
var context = SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(context);
userProfileProperties = peopleManager.getMyProperties();
context.load(userProfileProperties, 'PersonalUrl');
context.executeQueryAsync(success, fail);
}
function success(){
var mySiteUrl = userProfileProperties.get_personalUrl();
}
Make sure SP.UserProfiles.js
is loaded and user had read access to user profile in appmanifest.xml.
Garima's answer is fine but the problem is the PersonalUrl can be overwritten by the user. It remains as MySite Url when its pulled back in the code if its blank but if the user enters a value you get back that value instead of the MySite Url. A better function to use is get_userUrl().
So I'd change the above code to be:
function getPersonalUrl() {
var context = SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(context);
userProfileProperties = peopleManager.getMyProperties();
context.load(userProfileProperties, 'PersonalUrl');
context.executeQueryAsync(success, fail);
}
function success(){
var mySiteUrl = userProfileProperties.get_userUrl();
}
-
I guess UserUrl returns the my site host page (which is common for all with different query string parameter) of the user. It does not return the my site of the user. So Personal Url will return tenant-my.sharepoint.com/personal/user_mail while UserUrl will return tenant-my.sharepoint.com:443/…. So it depends on your requirement. – Garima Jan 23 '15 at 5:35