I tried this just for fun 😛 , enjoy
function check(){ExecuteOrDelayUntilScriptLoaded(updateProduct, “SP.js”);}function updateProduct() {var context = new SP.ClientContext.get_current();var web = context.get_web();var cldList = web.get_lists().getByTitle(“ChoiceFeild”);var categoryField = cldList.get_fields().getByInternalNameOrTitle(“Visa”);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 === “Dependent Visa”;});if (categoryTC.length == 0){categoryChoices = new Array();categoryChoices.push(“Dependent Visa”);categoryChoiceField.set_choices(categoryChoices);categoryChoiceField.updateAndPushChanges();context.executeQueryAsync(function () {alert(‘done’); }, function () {alert(‘failed’); });}}, function () { alert(‘failed’);});}<input type=’button’ id=’hello’ onclick=’check()’ value=’Add’/>
Leave a comment