1

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.

bumped to the homepage by Community 18 hours ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

Option 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

https://docs.microsoft.com/en-us/sharepoint/dev/spfx/extensions/get-started/building-simple-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.

0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.