In some cases, it could be necessary to hide a field in the editform in SharePoint. This could easily be done with the SetShowInEditForm() method from the Client-side Object Model of SharePoint.

In this short demo, I have prepared a demo list with the fields “Target Date” and “Planned Date”. When a new item is created by a user, both fields could be edited. But, when the item was saved, we do not want to be able to modify the value in the “Target Date”.

In the web interface in SharePoint, we do not have any option to change the necessary property of the field. But with PowerShell, this problem could easily be solved. After we have established a connection to our SharePoint site, we can use these four lines of script to do the modification:

When we are using a SharePoint site with modern UI, the field will always be removed, except when we add a new item, because the information pane is always opened in edit mode (in modern UI we do not have a separate view mode).

But when we switch back to the classic UI, we can see a difference.

Display form:

Edit form:

Just done, with a few lines in PowerShell.

Just, to have it complete: the Client-side Object Model has two other methods in the Field-class, SetShowInNewForm() and SetShowInDisplayForm(), to make a similar functionality available in the other forms for the list.

Yes, it is also possible to archive the same goal by modifying the edit form with PowerApps, when we use the modern UI. But this only works with the modern UI and there is still a need for using the classic UI, because we have other options in the classic interface actually not available in the modern UI.

 

Advertisements