Created
March 28, 2012 18:11
Revisions
-
gbutt revised this gist
Mar 28, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -37,5 +37,5 @@ // execute unit of work clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed); }, "sp.js"); </script> -
gbutt revised this gist
Mar 28, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,8 @@ var myAnnouncementText = document.getElementById('myAnnouncement').value(); // get the SP context and list var ctx = SP.ClientContext.get_current(); var targetList = ctx.get_web().get_lists().getByTitle('Announcements'); // create new list item var itemCreateInfo = new SP.ListItemCreationInformation(); -
gbutt revised this gist
Mar 28, 2012 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,7 @@ </div> <script type="text/javascript" > // Use this to delay execution until the file sp.js has loaded. Also a good way to keep your context free of globals. ExecuteOrDelayUntilScriptLoaded(function() { // get announcement text var myAnnouncementText = document.getElementById('myAnnouncement').value(); -
gbutt created this gist
Mar 28, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ <div> <label for="myAnnouncement">Announcement</label> <input id="myAnnouncement" type="text" /><br /> <input type="button" value="Post Announcement" /> </div> <script type="text/javascript" > ExecuteOrDelayUntilScriptLoaded(function() { // get announcement text var myAnnouncementText = document.getElementById('myAnnouncement').value(); // get the SP context and list var ctx = SP.ClientContext.get_current().get_web(); var targetList = ctx.get_lists().getByTitle('Announcements'); // create new list item var itemCreateInfo = new SP.ListItemCreationInformation(); var newListItem = targetList.addItem(itemCreateInfo); // set info for new item newListItem.set_item('Title', 'MyNewAnnouncement'); newListItem.set_item('Body', myAnnouncementText); newListItem.update(); // register unit of work with context ctx.load(newListItem); // we need to pass our newListItem to the onSuccess function. We do this with closure. Another method would be to use $.proxy var onQuerySucceeded = function() { var item = newListItem; alert('Announcement created!\n\nId: ' + item.get_id() + '\nTitle: ' + item.get_item('Title')); }; var onQueryFailed = function(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); }; // execute unit of work clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed); }, “sp.js”); </script>