0

I have used a POST before to send list items to SharePoint, although the only items that were included were text inputs so I could call the #id of that input and create the value like so:

var item = {
      "__metadata": { "type": "SP.Data.(ListName)TestListItem" },
      "Title": "No Title",
      "Example": $("#example").val()
};

This application, however, is a bit different and I have never used a method like it before. I have about 8 checkbox inputs that I need to concatenate all into one value, to post to my SharePoint list item "Q6", which has all of the same options as multiple choice values.

I will have my fiddle attached, but I cannot log the value that I am trying to use for my "Q6".

Here is my fiddle: https://jsfiddle.net/BeerusDev/y463j5gp/4/

Per Ganesh and I's comments, I updated var item to the following and I still get a "Bad Request"

var item = {
      "__metadata": { "type": "SP.Data.FeedbackNewHireTestListItem" },
      "Title": "No Title",
      "_x0051_1": $("#q1").val(),
      "_x0051_2": $("#q2").val(),
      "_x0051_3": $("#q3").val(),
      "_x0051_4": $("#q4").val(),
      "_x0051_5": $("#q5").val(),
      "_x0051_6": {"results": selectedValues},
      "_x0051_7": $("#q7").val(),
      "_x0051_8": $("#q8").val(),
      "_x0051_9": $("#q9").val(),
      "_x0051_10": $("#q10").val(),
      "_x0051_11": $("#q11").val(),
      "_x0051_12": $("#q12").val()
  };
1

Part of the problem is that you are already concatenating the values of the checkboxes into a string, and then you are trying to use the jQuery .val() function on that string, which you don't need to do.

From your fiddle:

var q6 = selectedValues.join(',');
  
console.log(q6); // this outputs a string, so you can see that the selected values appear to be concatenated correctly

But then when you are putting together your JSON payload for the SP list item, you have this:

// ...
"Q5": $("#q5").val(),
"Q6": $(q6).val(),    // this is not going to work
"Q7": $("#q7").val(),
// ...

You already have the value as a string in the q6 variable, you do not have to "re-val()" it to get the value, just use the variable directly:

// ...
"Q5": $("#q5").val(),
"Q6": q6,
"Q7": $("#q7").val(),
// ...
1

If you are trying to save the checkbox selections in multiple-selection choice field, you need to pass the data in below format:

'Status': { 'results':['Status 1', 'Status 2', 'Status 3'] }

So, for your case, try using this:

var item = {
      "__metadata": { "type": "SP.Data.(ListName)TestListItem" },
      "Title": "No Title",
      "Example": { "results": selectedValues }
};

Make sure you are using correct internal name for Example column.

Follow this article to find the internal name of column: Find the internal name of SharePoint column

16
  • Could I do: "Q6": { "results": q6} – BeerusDev Jun 15 at 16:52
  • It expects array of string. so better try using as given in my answer because you already have array stored in selectedValues. Let me know if that doesn't work for you. – Ganesh Sanap Jun 15 at 16:56
  • I tried the selectedValues, and even before you made this answer. With Dylan's answer as well, I keep getting a "Bad Request" – BeerusDev Jun 15 at 16:58
  • What is the data type of your column? If choice, is multiple selection enabled for this? What was the exact error message when you tried with selectedValues? – Ganesh Sanap Jun 15 at 17:00
  • Q6 is a choice column --> Display choices using --> Checkboxes (allow multiple selections). I will add a screenshot to OP – BeerusDev Jun 15 at 17:02

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.