0

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

  • Are you sure you can create the new site column with the same display name? – Ganesh Sanap Oct 29 '18 at 12:37
  • @GaneshSanap yes i can do so, i use to do so before many times.. also even in my above script if i chnage the Name & StaticName to be Department1 and i kept the DisplayName as Department the script will work well... so this mean that i can have 2 fields with the same display name using power-shell... – SharePoint TestDev Oct 29 '18 at 13:00
  • 1
    StaticName Department is used in outOftheBox Column i believe, you need to use different name. – Marek Sarad Oct 29 '18 at 14:27
  • @MarekSarad so you mean the built-in site column named Department have its display name =department + its internal name as ol_department + its static name = department ?? or there is another site column? – SharePoint TestDev Oct 29 '18 at 16:06
1

You are correct you can have 2 columns with the same display name. But normally at least in case of on prem there are 2 departments columns:

1 DL=Department, SN=Department, IN=Department 2.DL=Department, SN=ol_Departement, IN=ol_Department,

So you cannot create another column with same internal/static name. You need to either reuse this column or create with a slighty diferent name ie. "Dept."

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.