JSOM: Alter a column's DisplayName
By Anatoly Mironov
Here is another article in my JSOM series. For one month ago I showed how to alter a column’s ShowInDisplayForm property with JSOM. This time I’ll show a code sample for changing a column’s (field’s) display name. If you want to alter the displayname with Server Object Model, grab the code in the sharepoint.stackexchange.com: Change Field’s DisplayName in a List. [sourcecode language=“javascript”]var ctx = SP.ClientContext.get_current(), //SP.ClientContext field = ctx.get_web() //SP.Web .get_lists() //SP.ListCollection .getByTitle(‘MyList’) //SP.List .get_fields() //SP.FieldCollection .getByInternalNameOrTitle(“Body”); //SP.Field ctx.load(field, “Title”); //load only Title ctx.executeQueryAsync(function() { field.set_title(“Beskrivning”); field.update(); ctx.executeQueryAsync(); });[/sourcecode]
Comments from Wordpress.com
Bill - Mar 5, 2016
This will change the field’s Internal Name. I just want to change the field’s Display Name and keep the original Internal Name.
This will not change the InternalName, actually the Internal Name cannot be change. This will update the Display Name only.
Thanks for helping. We are using CSOM - Javascript - SharePoint 2013 We need to first create the field with a field name like xxxFieldName with no spaces. This will be our internal name. Now, we need to change the display name from xxxFieldName to ‘The Field Name’ without changing the internal name. Unfortunately, the internal name gets gets changed to ‘The Field Name’. &Field=The%5Fx0020%5FField%5Fx0020%5FName we need &Field=xxxTheFieldName We used PowerShell scripts before. It works fine. The field Internal names stay as they were when first created and only the display name changes. There are some significant bugs in CSOM Javascript.
Here is the answer to my question. When first creating the field using JSOM, I am using oFields.addFieldAsXml. The xml field node string MUST have the DisplayName attribute value set to the Internal Name before calling addFieldAsXml. Once the field is created, using set_title will not change the field’s Internal Name.