I want to update a Column Name using a Calculated Column. In my attempts below, I'm trying to rename the Column name from Col2change to NewName. None of the code snipperts work.
I do not have access to Workflows, etc. the only method I have available is via Calculated Columns.
Can anyone see the problem with my code?
=" <img src=""http://Oursite/blank.gif"" onload=""{"
&"var clientContext=new SP.ClientContext.get_current();"
& "var list=clientContext.get_web().get_lists().getById (SP.ListOperation.Selection.getSelectedList());"
&" var field = list.get_fields().getByInternalNameOrTitle(""Col2Change"");"
&" field.set_title(""NewName"");"
&" field.update();"
&" context.load(field);"
&" context.executeQueryAsync(); "
& " }"">"
=" <img src=""http://Oursite/blank.gif"" onload=""{"
&"var ctx = SP.ClientContext.get_current();"
&" field = ctx.get_web() "
&" .get_lists() "
&" .getByTitle('My List') "
&" .get_fields() "
&" .getByInternalNameOrTitle(""Col2change""); "
&"ctx.load(field, ""SchemaXml""); "
&"ctx.executeQueryAsync(function() {"
&" var s = field.get_schemaXml(),"
&" s1 = s.replace('Title=""Col2change""', "
&" 'ShowInDisplayForm=""NEWNAME""');"
&" field.set_schemaXml(s1);"
&" field.update();"
&" ctx.executeQueryAsync();"
& " } ) }"">"
=" <img src=""http://Oursite/blank.gif"" onload=""{"
&"var ctx = SP.ClientContext.get_current();"
&" field = ctx.get_web() "
&" .get_lists() "
&" .getByTitle('My List') "
&" .get_fields() "
&" .getByInternalNameOrTitle(""Columnname""); "
&"ctx.load(field, ""Title""); "
&"ctx.executeQueryAsync(function() {"
&" field.set_title(""UpdatedColumnname"");"
&" field.update();"
&" ctx.executeQueryAsync();"
& " } ) }"">"
=" <img src=""http://Oursite/blank.gif"" onload=""{"
&"var clientContext = SP.ClientContext.get_current();"
&"var List list = clientContext.Web.Lists.GetByTitle(""My List"");"
&" clientContext.Load(list);"
&" clientContext.ExecuteQuery();"
&" var fields = list.Fields;"
&" clientContext.Load(fields);"
&" clientContext.ExecuteQuery();"
&" var field = fields.GetByInternalNameOrTitle(""ColumnName"");"
&" var field.Title = ""NewColumnName"";"
&" field.Update();"
&" clientContext.Load(field);"
&"clientContext.ExecuteQuery();"
& " }"">"