1

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:-

enter image description 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 ?

6

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.

enter image description here

Meanwhile, I tried to check the parameter of Web.Fields.GetField that it takes the internal name or field display name.

enter image description here

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.

  • and what about the MSDN link i provide ? it say that it should accept internal names – john Gu Nov 22 '16 at 1:34
  • 1
    the above link is related to SPListItem class, not SPFields , meanwhile my attached image from visual studio, you can try it :) – Mohamed El-Qassas MVP Nov 22 '16 at 1:36
  • so can you adivce what is the differences between these (SPListItem & SPFields) ? i did not get your point – john Gu Nov 22 '16 at 1:37
  • 1
    SPListItem represents an item or row in a list. & SPField Represents a field in a list – Mohamed El-Qassas MVP Nov 22 '16 at 1:41
  • 1
    Additionally, to make sure my answer , Web.Fields.GetField and web.Fields both defined from SPField SPFieldCollection as It's shown at my print screen , Meanwhile, at Web.Fields.GetField it mention both internal name and display name , but web.Fields it only mentions display name , so if you know only the display name you should use web.Fields , hope it's now clear :) – Mohamed El-Qassas MVP Nov 22 '16 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.