Last active
June 30, 2023 14:44
-
-
Save vaderj/2e70c21a3e4d7cf0b602a260bd8e9dfc to your computer and use it in GitHub Desktop.
Add a new SP list item via REST API #Javascript #SharePoint #REST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function newEnrollment(firstName, lastName, email, team, classNameId ) | |
{ | |
var item = { | |
"__metadata": { "type": "SP.Data.EnrolleesListItem" }, // <=="type" derived from the target Lists name - getbytitle('Enrollees') = "SP.Data.EnrolleesListItem" | |
"Title": firstName, | |
"LastName": lastName, | |
"Team": team, | |
"Email": email, | |
"ClassNameId": classNameId | |
}; | |
//http://sharepoint.stackexchange.com/questions/105380/adding-new-list-item-using-rest | |
var newEnrollee = jQuery.ajax({ | |
//url: webUrl + "_api/web/lists/getbytitle('" + classesListName + "')/items?'" + classesColumns + "'&$filter=Title eq '" + lookup + "'" , | |
url: webUrl + "_api/web/lists/getbytitle('Enrollees')/items", | |
contentType: "application/json;odata=verbose", | |
data: JSON.stringify(item), | |
method: "POST", | |
headers: { "Accept": "application/json; odata=verbose","X-RequestDigest": $("#__REQUESTDIGEST").val()} | |
}); | |
newEnrollee.done(function(data, textStatus, jqXHR) | |
{ | |
try | |
{ | |
window.location.reload(); | |
} | |
catch(err) | |
{ | |
console.log(err) ; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment