inside my powershell script ,why i am able to reference a site column using its Display name , while can not reference it using its internal name
-
11-12-2020 - |
Frage
sometimes i can not understand how i need to write a robust power script inside sharepoint 2013, specifically when it comes to site columns Display Name versus internal names.
now i have the following site column, where its internal name is ItemNumber
while its Display name is Item Number
as shown here:-
now i wanted to assign this field a JSlink, so i tried the following script by referencing the site column using its internal name:-
$web = Get-SPWeb http://servername/
$field = $web.Fields["ItemNumber"]
$field.PushChangesToLists = $true
$field.JSLink = "~siteCollection/Resources/hideItemNumberinQucikEdit.js"
$field.update()
$web.Update()
$web.Dispose()
but i got this error on the 3rd line:-
PS C:\Users***> $field.PushChangesToLists = $true Property 'PushChangesToLists' cannot be found on this object; make sure it exists and is settable. At line:1 char:1 + $field.PushChangesToLists = $true + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound
now i modified my original script so inastead of using "ItemNumber" which represents the internal name, i used the "Item Number" which represents the display name, as follow:-
$web = Get-SPWeb http://servername/
$field = $web.Fields["Item Number"]
$field.PushChangesToLists = $true
$field.JSLink = "~siteCollection/Resources/hideItemNumberinQucikEdit.js"
$field.update()
$web.Update()
$web.Dispose()
and my script worked well. but still i am 100% confused. As i know that sharepoint understand internal names for the columns,, or it will look for internal and then display names,,, but what i can not understand is that when i use the column internal name the script did not work, but when i used the column display name the script worked!!
also as mentioned on this link https://msdn.microsoft.com/library/microsoft.sharepoint.splistitem
For an indexer based on a name, Microsoft SharePoint Foundation first looks for the field by internal name and then by display name.
so can anyone advice what is going on ?
Lösung
Because of the Powershell is not showing any description related to the data type of the value . so I tried to check the parameter type that should be passed to web.Fields
in visual studio and I found out :
The web.Fields[fieldname]
accepts only the display name and not the internal name of the field as shown below.
Meanwhile, I tried to check the parameter of Web.Fields.GetField
that it takes the internal name or field display name.
So if web.Fields
takes an internal name it should be mentioned in visual studio as it's shown for Web.Fields.GetField
.
So your above code will work only with the display name because of the web.Fields[fieldname]
accepts only the display name as I mentioned above.