TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
palutla sagar
NA
7
624
How to insert data into the list?
Jan 18 2017 1:36 PM
When I run the code in console the item is getting created with empty columns, but when I run same code with input values it is showing as request failed. Following is my code..Check it and help me...Thanks in advance
$(document).ready(function() {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Ideas')/items('69')?$select=IdeaId,Title",
method: "GET",
headers: { "Accept": "application/json; odata=verbose", "Content-Type": "application/json;odata=verbose", },
success: function (response) {
if (response.d != undefined) {
var ResultDiv = response.d;
$("#ideaId").val(ResultDiv.IdeaId);
$("#ideaDescription").val(ResultDiv.Title);
}
},
/*error: function (response) {
$("#ResultDiv").empty().text(responseJSON.error);
}*/
});
//Add an item to list
createListItem();
//Update an item
updateListItem();
});
function createListItem() {
use strict;
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle("RiskRatings");
var itemCreateInfo = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(itemCreateInfo);
var listItemRole = document.getElementById("txtraterrole").value;
alert(listItemRole);
var listItemName = document.getElementById("txtratername").value;
alert(listItemName);
var listItemRating = document.getElementById("txtrating").value;
alert(listItemRating);
var listItemComments = document.getElementById("txtriskcomments").value;
alert(listItemComments);
oListItem.set_item('RaterRole', listItemRole);
oListItem.set_item('RaterName', listItemName );
oListItem.set_item('Rating', listItemRating);
oListItem.set_item('RiskComments', listItemComments);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert('Item created: ' + oListItem.get_id());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
function clearFields(){
document.getElementById("txtraterrole").value="";
document.getElementById("txtratername").value="";
document.getElementById("txtrating").value="";
document.getElementById("txtriskcomments").value="";
}
Reply
Answers (
1
)
Get excel file from sharepoint,edit and save as CSV
HTTP Error 503. The service is unavailable.