<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script> <script type="text/javascript"> function GetFieldOptions() { return $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('mylist')/Fields(guid'2e257823-b8c6-411d-80f3-9f2cc913be0f')", type: "GET", headers: { "accept": "application/json;odata=verbose", "Content-Type": "application/json;odata=verbose" } }) } function updateChoiceField() { GetFieldOptions().done(function (data) { var FieldOptions = data.d.Choices.results; FieldOptions.push("NewOption"); $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('mylist')/Fields(guid'2e257823-b8c6-411d-80f3-9f2cc913be0f')", type: "POST", data: JSON.stringify({ "__metadata": { "type": "SP.FieldChoice" }, "Choices": { "__metadata": { "type": "Collection(Edm.String)" }, "results": FieldOptions } }), headers: { "accept": "application/json;odata=verbose", "X-RequestDigest": $('#__REQUESTDIGEST').val(), "Content-Type": "application/json;odata=verbose", "X-HTTP-Method": "PATCH", "IF-MATCH": "*", }, success: function (data) { console.log(data); }, error: function (error) { alert(JSON.stringify(error)); } }); }) } </script> <input id="Button1" onclick="updateChoiceField()" type="button" value="updateChoiceField" />
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter