In this blog, we will see how to get and set manager property of currently logged in user. We have a one-person editor field and we need to set the name of the manager based on the logged-in user.
I have one visual web part and in that, I have the following control.
The below-given script is used to get the manager name from SharePoint user profiles.
I have one visual web part and in that, I have the following control.
- <SharePoint:PeopleEditor MultiSelect="false" ValidationEnabled="true" ID="cppFirstApprover" Width="500px" runat="server" VisibleSuggestions="3" Rows="1" CssClass="ms-long ms-spellcheck-true marginleft0" />
- <script>
- LoadPeoplePickerDetails();
- //this function is used to get and set manager name to people editor field of SharePoint
- function LoadPeoplePickerDetails() {
- var url = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties"
- getReqData(url, function(data) {
- try {
- var ManagerName = data.d.UserProfileProperties.results[15].Value;
- $("div[id*='cppFirstApprover']").html(ManagerName);
- $("a[id*='cppFirstApprover_checkNames']").click();
- } catch (err) {}
- }, function(data) {
- alert("some error occured in getting current User info");
- });
- }
- function getReqData(reqUrl, success, failure) {
- $.ajax({
- url: reqUrl,
- method: "GET",
- headers: {
- "Accept": "application/json; odata=verbose"
- },
- success: function(data) {
- success(data);
- },
- error: function(data) {
- failure(data);
- }
- });
- }
- </script>

Piyush AgarwalPosted Mar 9, 2018, 6:55 AM
Hey Hi Rashmi, Can you please let me know why have we used results[15] . Is it specific to your requirement or is it applicable to sharepoint environment.