I am working on a sharepoint online enterprise wiki site collection. and i want to create a new site column named "Department" of type choice. now i already know that there is a built-in column which has a Display name = Department
of type single-line of text, but which has its internal name = ol_Department
.
so i know that i will not be able to create my site column using the UI, since i will get an error that the Department name already exists. but i use to add the column using power-shell script, since i will define a different internal name. so i try running this power-shell script:-
Add-Type -Path (Resolve-Path "$env:Common\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "$env:Common\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll")
#Site collection URL
$siteurl = "https://**********.sharepoint.com/sites/I*******/"
$userName ="admin@******.onmicrosoft.com"
$password ="**********"
#client context object and setting the credentials
[Microsoft.SharePoint.Client.ClientContext]$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl)
# convert password into secure string
$securedpassword = ConvertTo-SecureString $password -AsPlainText -Force
$clientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $securedpassword)
#get the rootweb
$site = $clientContext.Site
$web = $site.RootWeb
#Get fields collection
$fields = $web.Fields
$clientContext.Load($web)
$clientContext.Load($fields)
$clientContext.ExecuteQuery()
#your field xml
$fieldXML = "<Field Type='Choice'
Name='Department'
Description=''
DisplayName='Department'
StaticName='Department'
Group='Custom Columns'
Hidden='FALSE'
Required='TRUE'
Sealed='FALSE'
ShowInDisplayForm='TRUE'
ShowInEditForm='TRUE'
ShowInListSettings='TRUE'
ShowInNewForm='TRUE'>
<CHOICES>
<CHOICE>other</CHOICE>
</CHOICES>
</Field>"
$fields.AddFieldAsXml($fieldXML, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::AddToDefaultContentType)
$clientContext.Load($fields)
$clientContext.ExecuteQuery()
but this script raised the following error, and my column was not added:-
Exception calling "ExecuteQuery" with "0" argument(s): "A duplicate field name "Department" was found."
At line:20 char:1
+ $clientContext.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ServerException
as i mentioned i should be able to create site column which has existing display names as long as the internal name is unique,, so i am not sure why i am getting this error? is there any update on sharepoint online which is preventing us from doing so?
Thanks
Name
&StaticName
to beDepartment1
and i kept theDisplayName
asDepartment
the script will work well... so this mean that i can have 2 fields with the same display name using power-shell...department
+ its internal name asol_department
+ its static name =department
?? or there is another site column?