Friday, January 23, 2015

Update item using CSOM

 <script language="ecmascript" type="text/ecmascript">
    function updateListItem() {
        var clientContext = new SP.ClientContext.get_current();
        var oWeb = clientContext.get_web();
        var oListColl = oWeb.get_lists();
        var oList = oListColl.getByTitle(LISTNAME);    
        var oListItem = oList.getItemById(ITEMID);
        oListItem.set_item('testcolumn', 'Item Updated');
        oListItem.update();      
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }

    function onQuerySucceeded() {
        alert('Item updated successfully.');
    }
    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
</script>
<input onclick="updateListItem()" type="button" value="Update List Item"/>

Tuesday, January 20, 2015

Updating a column for a particular item in a list using LINQ

SPListItem resultItem = (from SPListItem oItem in oWeb.Lists["CustomList"].Items
                         where Convert.ToString(oItem["ColumnName"]) == 'Value'
                         select oItem).First();
resultItem["Title"] = "Sample";
resultItem.Update();