Saturday, 5 July 2014

Get Sharepoint User Profile Information of All Properties Using JavaScript

In this article we need to pass the user profile information, let's say Account Name, First Name, Last Name, PictureUrl and SPS-SipAddress and so on to some other function in JavaScript. For accessing the current logged in user information you need to call the GetUserProfileByName function of the userprofileservice web service. 

I have written a JavaScript code for accessing the GetUserProfileByName function of the userprofileservice web service:
function fetchUserProfileData() {
var art = null;
//IE
if (window.ActiveXObject) {
art = new ActiveXObject("Microsoft.XMLHTTP");
}//Mozilla, chrome, etc.,
else if (window.XMLHttpRequest) {
art = new XMLHttpRequest();
}
else {
throw new Error("XMLHttpRequest not supported");
}
if (art == nullreturn null;
art.Open("POST", _spPageContextInfo.webAbsoluteUrl+ “/_vti_bin/userprofileservice.asmx", false);
art.setRequestHeader("Content-Type""text/xml; charset=utf-8");
art.setRequestHeader("SOAPAction","http://microsoft.com/webservices/SharePointPortalServer/UserProfileService/GetUserProfileByName");
var Xsoap = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:tns=\"http://schemas.microsoft.com/sharepoint/soap/\"><soap:Body><GetUserProfileByName xmlns=\"http://microsoft.com/webservices/SharePointPortalServer/UserProfileService\"><AccountName>Domain\\UserName</AccountName></GetUserProfileByName></soap:Body></soap:Envelope>";
art.Send(Xsoap);
var xmlDoc = art.responseXML;
var strAccountSPSHireDate = "";
var elmValue = xmlDoc.getElementsByTagName("Value");
for (i = 0; i < elmValue.length; i++) {
if (elmValue[i].parentNode.parentNode.parentNode.childNodes[2].text =='SPS-HireDate
') {
strAccountSPSHireDate = elmValue[i].childNodes[0].nodeValue;
}
}
alert(strAccountSPSHireDate);
} 
List of User Properties
AccountName
DirectReports
DisplayName
Email
ExtendedManagers
ExtendedReports
IsFollowed
LatestPost
Peers
PersonalUrl
PictureUrl"
Title
UserProfileProperties
UserUrl

List of User Profile Properties
AboutMe
SPS-LastKeywordAdded
AccountName
SPS-Locale
ADGuid
SPS-Location
Assistant
SPS-MasterAccountName
CellPhone
SPS-MemberOf
Department
SPS-MUILanguages
EduExternalSyncState
SPS-MySiteUpgrade
EduOAuthTokenProviders
SPS-O15FirstRunExperience
EduPersonalSiteState
SPS-ObjectExists
EduUserRole
SPS-OWAUrl
Fax
SPS-PastProjects
FirstName
SPS-Peers
HomePhone
SPS-PersonalSiteCapabilities
LastName
SPS-PersonalSiteInstantiationState
Manager
SPS-PhoneticDisplayName
Office
SPS-PhoneticFirstName
PersonalSpace
SPS-PhoneticLastName
PictureURL
SPS-PrivacyActivity
PreferredName
SPS-PrivacyPeople
PublicSiteRedirect
SPS-ProxyAddresses
QuickLinks
SPS-RegionalSettings-FollowWeb
SID
SPS-RegionalSettings-Initialized
SISUserId
SPS-ResourceAccountName
SPS-AdjustHijriDays
SPS-ResourceSID
SPS-AltCalendarType
SPS-Responsibility
SPS-Birthday
SPS-SavedAccountName
SPS-CalendarType
SPS-SavedSID
SPS-ClaimID
SPS-School
SPS-ClaimProviderID
SPS-ShowWeeks
SPS-ClaimProviderType
SPS-SipAddress
SPS-ContentLanguages
SPS-Skills
SPS-DataSource
SPS-SourceObjectDN
SPS-Department
SPS-StatusNotes
SPS-DisplayOrder
SPS-Time24
SPS-DistinguishedName
SPS-TimeZone
SPS-DontSuggestList
SPS-UserPrincipalName
SPS-Dotted-line
SPS-WorkDayEndHour
SPS-EmailOptin
SPS-WorkDayStartHour
SPS-FeedIdentifier
SPS-WorkDays
SPS-FirstDayOfWeek
Title
SPS-FirstWeekOfYear
UserName
SPS-HashTags
UserProfile_GUID
SPS-HireDate
WebSite
SPS-Interests
WorkEmail
SPS-JobTitle
WorkPhone
SPS-LastColleagueAdded

Summary
We explored how to get the user profile property value using JavaScript and SharePoint services.

No comments:

Post a Comment

SharePoint 2013 - Uploading Multiple Attachments To The New Item On List Using JSOM And REST API

  Introduction In this article, we will explore how we can attach multiple attachments to the new item on list using JSOM and REST API. Ther...