0

During SharePoint migration from SP 2010 to 2013, the value of the column is displayed in HTML format instead of the person name as shown in the figure. enter link description here

enter image description here this field has the following properties enter image description here How to get the name of the person

We have not used SharePoint designer.

When we add an item ,owner of the role tab is displaying the current username by default and displaying in proper format but after saving the item, column value is shown in HTML format. enter image description here

The code you sent below is working when in AllItems view and there is no Group By

  <script src="https://code.jquery.com/jquery-1.12.4.min.js" 
  type="text/javascript"></script>
  <script type="text/javascript">
  SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
        OnPostRender: function(ctx) {
            var fieldIndex=0;
            var fieldName="Owner of the role";           
            $(".ms-listviewtable tr th").each(function(i){ 
                if($(this).find("a").text().indexOf(fieldName)!=-1){
                    fieldIndex=i;
                }           
            });
            $(".ms-listviewtable>tbody>tr").each(function(){
                var tdObj=$(this).children("td").eq(fieldIndex);
                tdObj.html(tdObj.html().replace(/&lt;/g, '<').replace(/&gt;/g, 
   '>'));
            });

        }
     });
 });
 </script>

But now when the AllItems view is Grouped By a column("Role"),then the script shared by you mentioned above is not working, After F12,we have observered that there is a differnece in internal Javascript after group by field("Role"). Please find the internal javascript script screenshot(Not full script) enter image description here

  • 1. Try to create a new view as it's problaby the rendering that is failing. Do the issue persist? Check if other lists have the same problem. 2. You have attached a image with sensitive information, such as a name, a mail adress and thereform the company and it's domain. You should replace or remove the picture. – Christoffer Jan 2 at 11:20
  • Yes , even in the new view it's the same for the Person or group column – sushma manne Jan 3 at 11:50
0

As a workaround, we can add the following code into a script editor web part in the list view page.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
        OnPostRender: function(ctx) {
            var fieldIndex=0;
            var fieldName="Owner of the role";           
            $(".ms-listviewtable tr th").each(function(i){ 
                if($(this).find("a").text().indexOf(fieldName)!=-1){
                    fieldIndex=i;
                }           
            });
            $(".ms-listviewtable>tbody>tr").each(function(){
                var tdObj=$(this).children("td").eq(fieldIndex);
                tdObj.html(tdObj.html().replace(/&lt;/g, '<').replace(/&gt;/g, '>'));
            });

        }
    });
});
</script>

If this field is a custom column, I suggest you check the source code of this custom column.

In SharePoint 2013, if you want to show the current user in user field by default in new item form. we can using the code below to achieve it. Create a new user field, copy the data from the issue field to the new field, add the code into script editor web part in new form page.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
    var userid = _spPageContextInfo.userId;
    function GetCurrentUser() {
        var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
        var requestHeaders = { "accept" : "application/json;odata=verbose" };
        $.ajax({
            url : requestUri,
            contentType : "application/json;odata=verbose",
            headers : requestHeaders,
            success : onSuccess,
            error : onError
        });
    }
    function onSuccess(data, request){
        var loginName = data.d.Title;
        SetUserFieldValue("Owner of the role",loginName);
    }
    function onError(error) {
    //alert(error);
    }
    function SetUserFieldValue(fieldName, userName) {
        var _PeoplePicker = $("div[title='" + fieldName + "']");
        var _PeoplePickerTopId = _PeoplePicker.attr('id');
        var _PeoplePickerEditor = $("input[title='" + fieldName + "']");
        _PeoplePickerEditer.val(userName);
        var _PeoplePickerObject = SPClientPeoplePicker.SPClientPeoplePickerDict[_PeoplePickerTopId];
        _PeoplePickerObject.AddUnresolvedUserFromEditor(true);
    }
    GetCurrentUser();
});
</script> 

If you add list view web part in home page, save the code below into a js file "convertHTML.js", and upload the file into Site Assets library, then reference the file in Web Part property JS LINK(~site/SiteAssets/convertHTML.js).

(function () { 

    // jQuery library is required in this sample 
    // Fallback to loading jQuery from a CDN path if the local is unavailable 
    (window.jQuery || document.write('<script src="https://code.jquery.com/jquery-1.12.4.min.js"><\/script>')); 
    // Create object that have the context information about the field that we want to change it's output render  
    var convertHTMLContext = {};
    convertHTMLContext.Templates = {};  
    convertHTMLContext.Templates.OnPostRender = convertHTMLOnPostRender; 
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(convertHTMLContext); 

})();

// This function provides the rendering logic 
function convertHTMLOnPostRender(ctx) {
    var fieldIndex=0;
    var fieldName="Owner of the role";           
    $(".ms-listviewtable tr th").each(function(i){ 
        if($(this).find("a").text().indexOf(fieldName)!=-1){
            fieldIndex=i;
        }           
    });
    $(".ms-listviewtable>tbody>tr").each(function(){
        var tdObj=$(this).children("td").eq(fieldIndex);
        tdObj.html(tdObj.html().replace(/&lt;/g, '<').replace(/&gt;/g, '>'));
    }); 
}
  • Thank you. This code is working fine for the list view page. But when this view is added as a web part in Home page, it is showing the same HTML format. Can you help me with this? – sushma manne Jan 2 at 5:30
  • Did you add the code into script editor web part in the Home Page? – LZ_MSFT Jan 2 at 6:16
  • Did not add in the script editor , added in the Content editor web part. Now it's working on list view page. But When we added the All Items List view as web part in main site collection home page, It's showing the same problem. – sushma manne Jan 2 at 8:48
  • Check my updated reply above. – LZ_MSFT Jan 2 at 8:53
  • Thankyou for your help.We tried but it's not working – sushma manne Jan 2 at 9:26
0

Open the list or view page in the designer & you will found the XSL code for the particular people editor showed

<xsl:value-of select=”@Column_x0020_Name”/>

You have to add another parameter disable-output-escaping=”yes” to that line. Now your code read for that line will be

<xsl:value-of select=”@Column_x0020_Name” disable-output-escaping=”yes”/>

Then after you will get desired output in your browser.

  • its' not showing in ShrepOint designer <xsl:value-of select=”@Column_x0020_Name”/>. – sushma manne Jan 2 at 8:38
  • You have to find your column name instead of @Column_x0020_Name in designer in XSLT View – Hardik Jan 2 at 8:42
  • I mean there is no such line – sushma manne Jan 2 at 8:50
0

When you edit your web Part, Under Miscellaneous, select the Server Render Checkbox. It is working fine for me.

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.