How to queue 'Personal Site'
When we work with Social features in SharePoint one main pre-requisite is 'User should have a personal site'.
Personal Site is self-service site collection, so once user clicks on "About me" links from the upper-right corner menu it will enable user’s personal site. But multiple time we need to provision user’s personal site via code on-demand.
In this article, we will enable Personal site using JavaScript.
Step by Step
The first step is to check if the user already has a “personal site”.
var
userHavePersonalSite =
false
;
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl +
"/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PersonalUrl"
,
method:
"GET"
async:
headers: {
"ACCEPT"
:
"application/json;odata=verbose"
"content-type"
},
success:
function
(data) {
//If user has personal site, set the variable to true
if
(data && data.d && data.d.PersonalUrl && data.d.PersonalUrl !=
""
&& data.d.PersonalUrl.indexOf(
"/personal/"
) != -1)
true
error:
(data) { }
})
_spPageContextInfo.formDigestValue
digest =
url:
"_api/contextinfo"
"POST"
digest = data.d.GetContextWebInformation.FormDigestValue;
(e) { oPleaseWaitDialog.close(); }
"/_api/sp.userprofiles.profileloader.getprofileloader/getuserprofile/createpersonalsiteenque(false)"
type:
"X-RequestDigest"
: digest },
//Showing wait dialog for 8 sec, rough time given to create personal site.
setTimeout(
() { oPleaseWaitDialog.close(); }, 8000)
});
//If user has personal site, set the variale to true
.done(
() {
//If user does not have personal site, adding request for creating 'Personal Site'. VMActivate.activateFollows
(!userHavePersonalSite) {
oPleaseWaitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose(
'Setting up things..'
, SP.Res.dialogLoading15);
}