A sample JS to modify the list choice field options.
var context = new SP.ClientContext.get_current(); var web = context.get_web(); var cldList = web.get_lists().getByTitle("Calendar"); var categoryField = cldList.get_fields().getByInternalNameOrTitle("Category"); var categoryChoiceField = context.castTo(categoryField, SP.FieldChoice); context.load(categoryChoiceField); context.executeQueryAsync(function () { var categoryChoices = categoryChoiceField.get_choices(); var categoryTC = categoryChoices.filter(function (choice) { return choice === "MyEvents"; }); if (categoryTC.length == 0) { categoryChoices.push("MyEvents"); categoryChoiceField.set_choices(categoryChoices); categoryChoiceField.updateAndPushChanges(); context.executeQueryAsync(function () { }, function () { }); } }, function () { });
The above script includes the specified option into the list choice field, if it doesn’t exist.