0

How to get/set multiple Checkbox value from/to Choice field using REST API.

Appreciate any reply in advance.

Thanks, MJ

0

We can use CSOM

Get value:

<script>
    var item;
    ExecuteOrDelayUntilScriptLoaded(GetListItem, "sp.js");  
    function GetListItem(){
        var clientContext = new SP.ClientContext.get_current();
        var web = clientContext.get_web();
        var list = web.get_lists().getByTitle("<list>");
        item = list.getItemById(<itemId>);
        clientContext.load(item);
        clientContext.executeQueryAsync(onSuccess, onFailure);
        }
        function onSuccess() {
            var checkboxValues = item.get_item("<checkbox column>");
            //operations
            console.log(checkboxValues);
        }
        function onFailure() {
            console.log('Failure!');
        }
</script>

Set value:

<script>
    ExecuteOrDelayUntilScriptLoaded(UpdateListItem, "sp.js");  
    function UpdateListItem(){
        var clientContext = new SP.ClientContext.get_current();
        var web = clientContext.get_web();

        var list = web.get_lists().getByTitle('<list>');
        var item = list.getItemById(<itemID>);
        //set multi-choice field 
        item.set_item('<checkbox column>', '<value1>', '<value2>');
        item.update();
        clientContext.executeQueryAsync(onSuccess, onFailure);
    }
    function onSuccess() {
        console.log("Item updated");
    }
    function onFailure() {
        console.log('Failure!');
    }
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.