Return to Snippet

Revision: 29173
at July 23, 2010 07:52 by rumremix


Initial Code
<script type="text/javascript">   

ExecuteOrDelayUntilScriptLoaded(functionName, "sp.js");  //this is necessary to ensure the library is loaded before function triggered 


function functionName() {


var clientContext = SP.ClientContext.get_current();
var myList = clientContext.get_web().get_lists().getByTitle('myList'); //actual list name here

var itemCreationInfo = new SP.ListItemCreationInformation();
var listItem = myList.addItem(itemCreationInfo);

listItem.set_item("Title", "the title"); //actual field names go in first argument, new assigned value in second
listItem.set_item("Field2", "tuna"); 
listItem.set_item("Field3", "ape");
listItem.set_item("Field4", "moose");


listItem.update();

clientContext.executeQueryAsync(Function.createDelegate(this,this.Succeeded),Function.createDelegatethis,this.Failed));
}


function Succeeded() {
alert("Succeeded");
}
function Failed(sender,args) {
alert("fail");
}



 
</script>

Initial URL


Initial Description
This code works for me without requiring any includes, plugins, or service packs. It should also integrate seamlessly with jquery.

Initial Title
sharepoint 2010 write to list using ecmascript

Initial Tags
javascript, list, object, sharepoint

Initial Language
JavaScript