It throws error when I try to create and add column in list which contains special characters such as '&'.
I tried following:
DisplayName="a&b" Name="a&b" -------- throws error
DisplayName="a& ;b" Name="a& ;b" -------- throws error (remove space before';')
DisplayName="a& ;b" Name="a_x0026_b" -------- works fine (remove space before';')
Do I really need to convert special characters to their respective special codes for example '&' to 'x0026' ?
Is there any official document saying that ?
function addFields() {
var clientContext = new SP.ClientContext.get_current();
var oWebsite = clientContext.get_web();
//Getting reference to the list
oList = clientContext.get_web().get_lists().getByTitle('List1');
var f2 = clientContext.castTo(
oList.get_fields().addFieldAsXml('<Field Type="Choice" DisplayName="a&b" Name="a&b" />', true,
SP.AddFieldOptions.addToDefaultContentType),
SP.FieldChoice);
var choices = Array("Approved", "Rejected", "Progress");
f2.set_choices(choices);
f2.update();
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
function onQuerySucceeded() {
alert("List Field Updated");
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
addFields()