0

Good morning, I'm trying to set a multiple select (checkbox) SharePoint item via bootstrap form independent of SharePoint's forms. I can get everything to work except passing the joined checkbox values to the SharePoint list item via REST.

    <div class="form-group" id="Point-Tags-FG">
        <div class="checkbox">
            <label><input type="checkbox" name="chkA" value="1">1</label>
        </div>
        <div class="checkbox">
            <label><input type="checkbox" name="chkB" value="2">2</label>
        </div>
        <div class="checkbox">
            <label><input type="checkbox" name="chkC" value="3">3</label>
        </div>
    </div>

    var url = ".../ListName";
    var event = $("#Event-Type").val();
    var date = $("#Event-Date-Time").val();
    var address = $("#Point-Address").val();
    var latitude = $("#Point-Latitude").val();
    var longitude = $("#Point-Longitude").val();
    var description = $("#Point-Description").val();

    var tags = []; 
    if ($('input[name="chkA"]').is(':checked')) {
        tags.push("1");
    }
    if ($('input[name="chkB"]').is(':checked')) {
        tags.push("2");
    }
    if ($('input[name="chkC"]').is(':checked')) {
        tags.push("3");
    }

    var SpecialTags = {"__metadata":{"type":"Collection(Edm.String)"},"results":[tags.join(',')]};

    var info = {
        __metadata: {type: "SP.Data.ListName"},
        PostId: post,
        EventValue: event,
        Date: date,
        Address: address,
        Latitude: latitude,
        Longitude: longitude,
        Description: description,
        Tags: SpecialTags
    };

    var body = JSON.stringify(info);

    $.ajax({
        type: "POST",
        url: url,
        contentType: 'application/json',
        processData: false,
        data: body,
        error: function (err) {console.log(err)},
        success: function (data) {
            alert(Entry Submitted.');               
            location.reload();
        }
    });

Unfortunately, every time the function is submitted it results in a console error POST URL 400 (Bad Request). I've looked around at some other examples here and can GET the information I just can't seem to POST it via 2010 which I'm stuck using for now.

0

The json value of multi-choice field value in the provided example is specified properly but not the Content Type header.

Since you are passing metadata tag, the valid Content Type header should be application/json;odata=verbose. Another supported content types are:

  • accept: application/json; odata=minimalmetadata //minimalmetadata
  • accept: application/json; odata=nometadata //nometadata

Follow this article for a more details.

You could also get more information about error by specifying for example, error callback for jQuery.ajax():

error: function( jqXHR, textStatus){
     console.log(jqXHR.responseText); 
}

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.