Partager via


SharePoint - Setting a View Definition

I try to encourage a minimalist approach towards working with SharePoint.   Why write code, when a community is doing it on a larger scale?  I absolutely love the PnP Provisioning engine and typically use it in conjunction with ensuring multiple environments stay in sync with the original site definition (think Desired State Configuration (DSC)).   Users typically (with more permissions than required) love to and occasionally change things.    This post is meant for a developer/team who might be working on a way to filter a SharePoint List/Library view where the application requirements go beyond what the User Interface will allow.  The developer might want to skip waiting for the Provisioning engine to run through everything just to update a View Definition.  Or, production was inadvertently updated and the view definition needs to be reset.

I received some requirements which included a large number of filters and boolean logic.  I immediately knew the UI was not going to be effective for creating a complicated query.   The requirements included making the data read-only and in some cases the user selection needed to pull from a separate list.  I knew I could update the XML in the Provisioning Engine schema and things would update the next time it ran.   The challenge with Agile development is not knowing what will shift from sprint to sprint.   I needed a way to quickly update a view definition and render the results to the user and application.   Enter a new Powershell CmdLet that can update any property of a List View definition.  By following the snippet below you can update the CAML query and/or update the JS Link property thus running code as the View is being rendered.

For code snippets you can view sample script and details here https://github.com/pinch-perfect/Infrastructure-As-Code/blob/master/HowToExtend/Gist/set-iac-viewdefinition.md