Last active
December 22, 2015 09:49
-
-
Save rheid/6454610 to your computer and use it in GitHub Desktop.
SharePoint 2013 REST Call to a List Item
This file contains 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
// Adding a list item with the metadata provided | |
function addListItem(url, listname, metadata, success, failure) { | |
// Prepping our update | |
var item = $.extend({ | |
"__metadata": { "type": getListType(listname)} | |
}, metadata); | |
// Executing our add | |
$.ajax({ | |
url: url + "/_api/web/lists/getbytitle('" + listname + "')/items", | |
type: "POST", | |
contentType: "application/json;odata=verbose", | |
data: JSON.stringify(item), | |
headers: { | |
"Accept": "application/json;odata=verbose", | |
"X-RequestDigest": $("#__REQUESTDIGEST").val() | |
}, | |
success: function (data) { | |
success(data); // Returns the newly created list item information | |
}, | |
error: function (data) { | |
failure(data); | |
} | |
}); | |
} | |
This file contains 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 CreateTeamsite() { | |
var url = _spPageContextInfo.siteAbsoluteUrl; | |
teamsiteValues = { | |
"Title": $('input[id=ctl00_PlaceHolderMain_txt_name]').val(), | |
"BusinessUnit": $("#sel_bu option:selected").text(), | |
"Description_x002f_Purpose":"test", // $('input[id=ctl00_PlaceHolderMain_txt_purpose]').val(), | |
"Members": peoplePicker_Members.GetAllUserKeys(), | |
"SecondaryOwner": peoplePicker_secondaryOwner.GetAllUserKeys(), | |
"Viewers": peoplePicker_Viewers.GetAllUserKeys(), | |
"Function": $("#sel_function option:selected").text(), | |
"SeoKeywords": "test", //$('input[id=ctl00_PlaceHolderMain_txt_keywords]').val(), | |
"Language1": $('input[id=ctl00_PlaceHolderMain_txt_language]').val(), //need to add this to the form | |
"PrimaryOwner": peoplePicker_secondaryOwner.GetAllUserKeys(), //TODO: get the logged in user's login id | |
"TimeZone1": $("#sel_timezone option:selected").val(), | |
"TypeofTeamsite": $("input[name=type]:checked").val(), | |
"URL": $('input[id=ctl00_PlaceHolderMain_txt_Url]').val() | |
}; | |
var outputstring = "Confirm and Submit<br />"; | |
for (var key in teamsiteValues) { | |
if (teamsiteValues.hasOwnProperty(key)) { | |
outputstring += key + " -> " + teamsiteValues[key] + '<br />'; | |
} | |
} | |
$('#confirm').html(outputstring); | |
submitTeamsite(); | |
} | |
function submitTeamsite() | |
{ | |
var url = _spPageContextInfo.siteAbsoluteUrl; | |
//var url = "http://teams.cce.com"; //TODO: pull this value from configuration later | |
$.ajax({ | |
url: url + "/_api/web/lists/getbytitle('" + listName + "')/items", | |
type: "POST", | |
contentType: "application/json;odata=verbose", | |
data: JSON.stringify(teamsiteValues), | |
headers: { | |
"Accept": "application/json;odata=verbose", | |
"X-RequestDigest": $("#__REQUESTDIGEST").val() | |
}, | |
success: function () { $('#message').text("Teamsite successfully submitted."); }, | |
error: function (jqXHR, textStatus, errorThrown) { $('#message').text("Update failed." + jqXHR.responseText + " " + errorThrown.toString()) } | |
}); | |
} | |
Update: I have found the answer to most of my question |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment