none
SharePoint 2013 views issue while updating webpart property through code RRS feed

  • Question

  • I'm updating the JSLink property of a listviewwebpart through powershell code on a SP2013 on prem site. The code is not throwing any errors, however the html of the webpart is changing completely.

    In the old view there is a checkbox in the first column of the view and the changed view as a tick as the first column for selecting all the rows.

    Can someone please help me with this issue to update the view through code without modifying the html.


    Regards, Shruti


    Tuesday, October 8, 2019 3:57 PM

All replies

  • Hi,

    Could you share the PowerShell logic so we could try to research/test?

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, October 9, 2019 1:10 AM
  • Hi Lee,

    I'm using the below script for adding property link.

    # Add Snapin  
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)   
    {  
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"  
    }  
     
    # Update Page  
    $web = Get-SPWeb <web url>
    $page = $web.Url + <view page url>  
    $file = $web.GetFile($page)    
    $file.CheckOut();    
    $manager = $web.GetLimitedWebPartManager($page, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)  
    $webpart = $manager.WebParts[0]  
    $webpart.JSLink = "~sitecollection/_catalogs/masterpage/UpdateEditLink.js"  
    $manager.SaveChanges($webpart);  
    $file.CheckIn("Updated property through code");


    Regards, Shruti

    Wednesday, October 9, 2019 9:43 AM
  • Can you please share the jslink code as well since it did not throw any error? Do you see on the jslink in web part properties on the UI?


    Please remember to up-vote & mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, October 9, 2019 11:16 AM
  • Hi Harshal,

    The code is not throwing any errors and is working fine. I can see the property value updated in the webpart properties window. The only problem is that the full html of listview webpart is changed after the update.

    Below is the image of the view before updating the property.

    This second image is of the same view after the property was changed through powershell. I inspected elements in IE and found that html of both the views is different.


    Regards, Shruti

    Wednesday, October 9, 2019 11:39 AM
  • Hi ,

    You need to know the js logic you’re setting(UpdateEditLink.js).

    As JSLink will override SharePoint field render based on your js logic.

    You could check below thread for more details about jslink(CSR).

    https://www.codeproject.com/Articles/620110/SharePoint-Client-Side-Rendering-List-Views

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, October 10, 2019 7:47 AM
  • Thanks for you reply Lee!

    I had gone through that article and copied the code from clienttemplate.debug.js file to my js file without doing any modifications. This is not working for me.

    I had previously read about default jslink files getting overridden when applying custom js files.

    I was trying to find the default jslink file for the original view. I checked the network traffic and found that neither clienttemplates.js nor clienttemplates.debug.js were being invoked.

    Whereas for the new view, I can see clienttemplates.js getting loaded and I assume that's the default for the modfied view.

    Will you please be able to explain why the original page doesn't have a default jslink and modified view page has it.


    Regards, Shruti


    Thursday, October 10, 2019 11:30 AM
  • Hi,

    OOB list without customization, clienttemplates.js is OOB rendering.

    https://social.technet.microsoft.com/wiki/contents/articles/29764.sharepoint-2013-an-introduction-to-jslink.aspx


    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, October 11, 2019 7:33 AM
  • Yes, clienttemplate.js is OOB js for rendering listview webpart. However, the existing view doesn't use it. When modifying JSLink property, clienttemplate.js is loaded and the html is changed. I tried modifying ChromeType property of webpart and it gets updated without changing the html. It is JSLink property which is modifying the html.

    Regards, Shruti

    16 hours 39 minutes ago