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
sagar Jinturkar
NA
214
4.2k
Updating List Items
Apr 24 2018 4:17 AM
$(document).ready(function() {
alert("button click");
$('#Button1').click(function(){
Button1_onclick();
});
$('#btn_Update').click(function(){
updateListItem();
});
});
function Button1_onclick() {
var title = $('#txtTitle').val();
var body = $('#txtBody').val();
createListItem(title,body);
}
function createListItem( ttl, bdy) {
alert(ttl+" "+ bdy);
var clientContext = SP.ClientContext.get_current();
var web = clientContext.get_web();
var lists = web.get_lists();
var oList = lists.getByTitle('Announcements');
var itemCreateInfo = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', ttl);
oListItem.set_item('Body', bdy);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert('Item created: ');
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
function updateListItem() {
alert("updateListItem");
var clientContext = SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Announcements');
var query = "<View><Query><Where><Eq><FieldRef Name='EmpID'/><Value Type='Text'>102</Value></Eq></Where></Query></View>";
camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(query);
items = oList.getItems(camlQuery);
clientContext.load(items);
/*
this.oListItem = oList.getItemById(3);
oListItem.set_item('Title', 'My Updated Title');
oListItem.update();*/
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
var companyEnum = items.getEnumerator();
while (companyEnum.moveNext()) {
var currentCompany = companyEnum.get_current();
var thisCompanyId = currentCompany.get_item('ID');
alert(thisCompanyId);
}
this.oListItem = oList.getItemById(4);
oListItem.set_item('Title', 'My new Title');
oListItem.set_item('Body', 'Thank You');
oListItem.update();
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
Reply
Answers (
3
)
SharePoint Forms Based Authentication C# Code (Add New User)
Error in custom Content type