I've currently got a script that, if I don't include the parameter Mission_Number - will work just fine to create a new list item. Whenever I try to pass that parameter, I get an error 500 (Internal Server Error).
Here is my list setup:
Ticket Number = Single Line of Text
DV = Choice
Tail Number = Choice
Mission Number = Single Line of Text
Here is my javascript:
var hostUrl = "mysite";
var listName = "Tickets";
$(document).on('click', '#ticket_submit', function() {
var ticket_number = $("#ticket_number").val();
var dv = $("#dv_select").val();
var tail_number = $("#tail_number").val();
var mission_number = $("#mission_number").val();
var itemProperties = {'Ticket_Number':ticket_number,'DV':dv,'Tail_Number':tail_number,'Mission_Number':mission_number};
console.log(itemProperties);
CreateListItemWithDetails(listName, hostUrl, itemProperties, function () {
alert("New Item has been created successfully.");
}, function () {
alert("Ooops, an error occured. Please try again.");
});
});
//
function CreateListItemWithDetails(listName, webUrl, itemProperties, success, failure) {
var itemType = GetItemTypeForListName(listName);
itemProperties["__metadata"] = { "type": itemType };
$.ajax({
url: webUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(itemProperties),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": digest // getting this from a function not shown here
},
success: function (data) {
success(data);
},
error: function (data) {
failure(data);
}
});
}
Here is an example of the JSON that I am passing that does not work:
{Ticket_Number: "2020-310-0001", DV: "ccxcc", Tail_Number: "12312", Mission_Number: "123123"}
Its odd to me that the ticket_number value is passing just fine, but the mission_number one is not. I have double checked in the sharepoint that I am using the proper column names as well.
Turns out, I accidentally had the ticket number column set as requires unique.. Problem has been fixed.