I have added a custom column named "Date" inside my announcement list, but i want to hide this column from the DispForm.aspx page. i tried the following two methods to hide the Date column but none of them worked:-
inside the DispForm.aspx, i add the following code:-
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> <script type="text/javascript"> var control = findacontrol("Date"); control.parentNode.parentNode.style.display="none"; function findacontrol(FieldName) { var arr = document.getElementsByTagName("!"); // get all comments for (var i=0;i < arr.length; i++ ) { // now match the field name if (arr[i].innerHTML.indexOf(FieldName) > 0) { return arr[i]; } } }
but it did not hide the Date field.
i also try the following power shell script:-
# First load SharePoint Core Assembly [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
$url = "http://sharepointdev/"; $list = "List"; $fieldname = "Date"; #Setting up context $$contextWeb = Get-SPWeb http://sharepointdev; $list = $contextWeb.Lists.TryGetList($list); $field = $list.Fields[$fieldname]; # Controls Field in Edit Form $field.ShowInEditForm = 1; # Controls Field in New Form $field.ShowInNewForm = 0; # Controls Field in New Form $field.ShowInDisplayForm = 1; # Hides fields from list settings $field.ShowInListSettings = 1; # Hides fields from version history $field.ShowInVersionHistory = 1; # Hides fields form selection in views $field.ShowInViewForms = 1; # Don't forget to update this field $field.Update(); # And finally dispose everything. $contextWeb.Dispose(); $contextSite.Dispose();
but i got the following errorinside the power shell window:-
PS C:\Users\Administrator> $list = $contextWeb.Lists.TryGetList($list); You cannot call a method on a null-valued expression. At line:1 char:1 + $list = $contextWeb.Lists.TryGetList($list); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
so can anyone advice on how i can hide the custom column from my announcement APP?
EDIT
Here is the updated code:-
$url = "http://sharepointdev/";
$list = "News & Announcement";
$fieldname = "Date";
#Setting up context
$webApp = Get-SPWebApplication http://sharepointdev
$list = $contextWeb.Lists.TryGetList($list);
$field = $list.Fields[$fieldname];
# Controls Field in Edit Form
$field.ShowInEditForm = 1;
# Controls Field in New Form
$field.ShowInNewForm = 1;
# Controls Field in New Form
$field.ShowInDisplayForm = 0;
# Hides fields from list settings
$field.ShowInListSettings = 1;
# Hides fields from version history
$field.ShowInVersionHistory = 1;
# Hides fields form selection in views
$field.ShowInViewForms = 1;
# Don't forget to update this field
$field.Update();
# And finally dispose everything.
$contextWeb.Dispose();
$contextSite.Dispose();
but it is raising the following error:-
> PS C:\Users\Administrator> $webApp = Get-SPWebApplication
> http://sharepointdev PS C:\Users\Administrator> PS
> C:\Users\Administrator> $list = $contextWeb.Lists.TryGetList($list);
> You cannot call a method on a null-valued expression. At line:1 char:1
> + $list = $contextWeb.Lists.TryGetList($list);
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + CategoryInfo : InvalidOperation: (:) [], RuntimeException
> + FullyQualifiedErrorId : InvokeMethodOnNull