Last active
June 30, 2023 14:43
-
-
Save vaderj/fa2800448e25f1bb8ae8aa7e44d08542 to your computer and use it in GitHub Desktop.
New SPListItem via SPREST API #Javascript #REST #SharePoint
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" }, | |
"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