I am programatically adding new fields to a list through Javascript. My code looks like:
var addColumnToList = function(title, fieldName, type) {
var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(title);
this.field = list.get_fields().addFieldAsXml("<Field DisplayName='" + fieldName + "' Type='" + type + "' />", true, SP.AddFieldOptions.defaultValue);
var fieldNumber = context.castTo(field, SP.FieldNumber);
fieldNumber.update();
context.load(field);
context.executeQueryAsync(
Function.createDelegate(this, this.onColAddSuccess),
Function.createDelegate(this, this.onColAddFail)
);
};
var onColAddSuccess = function() {
console.log(field.get_title() + " successfully added to list!\n");
};
var onColAddFail = function(sender, args) {
console.log("Add column request failed! " + args.get_message());
};
The default value of every item defaults to "null". My question is: Is there any way to specify a default value for all items when adding a new field to a SP list?