we have requirement to customize the display form. we need to show user profile properties for the user who has modified the item in the display form.
any help would be appreciated.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityOption 1 :You can attach a JSLink to your fields and in that javascript you can write js code to call your user profile service based on Modified by column and populate into a custom DIV.
Below are few code samples available using JSLink
https://code.msdn.microsoft.com/office/Client-side-rendering-JS-2ed3538a
Option 2 :SPFx extension field Customizer
With JSLink i have done a similar code where we need to query User profile service when user enter the username and populate other data in columns. so it was achievable.
We can use User Profile REST API with jQuery to achieve it. The following code for your reference, add the code into a script editor web part in the display form page.
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var displayName=$("table.ms-formtoolbar td.ms-descriptiontext:contains('Last modified at')").find("a.ms-peopleux-userdisplink").text();
var accountName=GetAccountName(displayName);
var requestUri = _spPageContextInfo.webAbsoluteUrl +
"/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='"+accountName+"'";
//execute AJAX request
$.ajax({
url: requestUri,
type: "GET",
headers: { "ACCEPT": "application/json;odata=verbose" },
async: false,
success: function (data) {
var userProperties=data.d.UserProfileProperties.results;
var htmlTable='<table width="100%" border="0" cellspacing="0" cellpadding="2">';
$.each(userProperties,function(i,property){
htmlTable+="<tr><td>"+property.Key+"</td><td>"+property.Value+"</td></tr>";
});
htmlTable+="</table>";
$("table.ms-formtoolbar").after(htmlTable);
},
error: function () {
//alert("Failed to get details");
}
});
});
function GetAccountName(displayName){
var accountName="";
var requestUri = _spPageContextInfo.webAbsoluteUrl +
"/_api/web/siteusers?$select=LoginName&$filter=Title eq '"+displayName+"'";
//execute AJAX request
$.ajax({
url: requestUri,
type: "GET",
headers: { "ACCEPT": "application/json;odata=verbose" },
async: false,
success: function (data) {
if(data.d.results.length>0){
accountName=data.d.results[0].LoginName.replace("#","%23");
}
},
error: function () {
//alert("Failed to get details");
}
});
return accountName;
}
</script>