Previously, we discussed about part 1 of the series.

Here are the steps for part 2 of the series,
Step 1: User Interface Design to perform CRUD operation with Office 365 SharePoint List.


In order to continue further I will add new files into project solution as in the following screenshot,


Source Code: To generate user interface we need html controls on page. Please refer the following code in order to create above user interface.

  1. <%@ Page Language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  2. <%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  3. <%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  4. <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  5. <asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
  6. <SharePoint:ScriptLink Name="sp.js" runat="server" OnDemand="true" LoadAfterUI="true" Localizable="false" />
  7. <script src="../Scripts/jquery-1.8.2.js" type="text/javascript"></script>
  8. <script src="../Scripts/AdvanceLibrary.js" type="text/javascript"></script>
  9. <link href="../Content/App.css" rel="stylesheet" />
  10. </asp:Content>
  11. <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
  12. <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="full" Title="loc:full" />
  13. <div>
  14. <div class="bodyLeft">
  15. <div>
  16. List Name :
  17. <input type="text" id="txtListName" />
  18. </div>
  19. <hr />
  20. <div>
  21. <h2><b>List Creation</b></h2>
  22. <a href="#" onclick="Wingtip.JSOMHostWebCollections.HWCreateList()">Create List</a>
  23. </div>
  24. <hr />
  25. <div>
  26. <h2><b>Add List Item</b></h2>
  27. <%-- <br />
  28. List Name :
  29. <input type="text" id="txtExistingListName" />--%>
  30. <table>
  31. <tr>
  32. <th>Field Name</th>
  33. <th>Field Value</th>
  34. </tr>
  35. <tr>
  36. <td>
  37. <input type="text" id="Input1" />
  38. </td>
  39. <td>
  40. <input type="text" id="Val1" />
  41. </td>
  42. </tr>
  43. <tr>
  44. <td>
  45. <input type="text" id="Input2" />
  46. </td>
  47. <td>
  48. <input type="text" id="Val2" />
  49. </td>
  50. </tr>
  51. <tr>
  52. <td>
  53. <input type="text" id="Input3" />
  54. </td>
  55. <td>
  56. <input type="text" id="Val3" />
  57. </td>
  58. </tr>
  59. <tr>
  60. <td>
  61. <input type="text" id="Input4" />
  62. </td>
  63. <td>
  64. <input type="text" id="Val4" />
  65. </td>
  66. </tr>
  67. </table>
  68. <br />
  69. <a href="#" onclick="Wingtip.JSOMHostWebCollections.HWCreateListItem()">Add List Data</a>
  70. </div>
  71. <hr />
  72. <div>
  73. <h2><b>Update List Item</b></h2>
  74. <%-- <br />
  75. List Name :
  76. <input type="text" id="txUpdationList" />--%>
  77. <table>
  78. <tr>
  79. <th>Field Name</th>
  80. <th>Field Value</th>
  81. </tr>
  82. <tr>
  83. <td>
  84. <input type="text" id="UpdateField1" />
  85. </td>
  86. <td>
  87. <input type="text" id="UpdateVal1" />
  88. </td>
  89. <td>Where ID =
  90. <input type="text" id="txtUpdateID" />
  91. </td>
  92. </tr>
  93. </table>
  94. <a href="#" onclick="Wingtip.JSOMHostWebCollections.HWUpdateListItem()">Update List Data</a>
  95. </div>
  96. <hr />
  97. <div>
  98. <h2><b>Delete List Item</b></h2>
  99. <%-- <br />
  100. List Name :
  101. <input type="text" id="txtListDeletion" />--%>
  102. Where ID =
  103. <input type="text" id="txtDeletionID" />
  104. <br />
  105. <a href="#" onclick="Wingtip.JSOMHostWebCollections.HWDeleteListItem()">Delete List Data</a>
  106. </div>
  107. </div>
  108. <div class="bodyRight">
  109. <div id="message"></div>
  110. <div id="ListData"></div>
  111. </div>
  112. </div>
  113. </asp:Content>

Step 2: Read List Data using custom JavaScript Library.

  1. var clientContext;
  2. var factory;
  3. var appContextSite;
  4. var web;
  5. var collList;
  6. var itemCreateInfo;
  7. var param1, param2, param3;
  8. var oList, targetList, listFields, oListItem, oField, itemId;
  9. var ExsitingListNameVal;
  10. var targetList;
  11. window.Wingtip = window.Wingtip || {}
  12. Wingtip.JSOMHostWebCollections = function()
  13. {
  14. LoadlayoutsJS = function()
  15. {
  16. //debugger
  17. hostweburl = decodeURIComponent(Wingtip.JSOMHostWebCollections.QSParameter("SPHostUrl"));
  18. appweburl = decodeURIComponent(Wingtip.JSOMHostWebCollections.QSParameter("SPAppWebUrl"));
  19. var Sessionhostweburl = sessionStorage.getItem("hostweburl");
  20. var Sessionappweburl = sessionStorage.getItem("appweburl");
  21. if (Sessionhostweburl == null || Sessionappweburl == null)
  22. {
  23. sessionStorage.setItem("hostweburl", hostweburl);
  24. sessionStorage.setItem("appweburl", appweburl);
  25. }
  26. if (hostweburl == null || appweburl == null || hostweburl == 'undefined' || appweburl == 'undefined')
  27. {
  28. hostweburl = sessionStorage.getItem("hostweburl");
  29. appweburl = sessionStorage.getItem("appweburl");
  30. }
  31. var scriptbase = hostweburl + "/_layouts/15/";
  32. $.getScript(scriptbase + "SP.Runtime.js",
  33. function() {
  34. $.getScript(scriptbase + "SP.js",
  35. function() {
  36. $.getScript(scriptbase + "SP.RequestExecutor.js", Wingtip.JSOMHostWebCollections.HWLoadClientContext);
  37. }
  38. );
  39. });
  40. }
  41. getQueryStringParameter = function(paramToRetrieve)
  42. {
  43. //debugger
  44. try {
  45. var params =
  46. document.URL.split("?")[1].split("&");
  47. var strParams = "";
  48. for (var i = 0; i < params.length; i = i + 1)
  49. {
  50. var singleParam = params[i].split("=");
  51. if (singleParam[0] == paramToRetrieve)
  52. return singleParam[1];
  53. }
  54. } catch (ex) {
  55. }
  56. }
  57. LoadClientContext = function()
  58. {
  59. //debugger
  60. clientContext = new SP.ClientContext(appweburl);
  61. factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
  62. clientContext.set_webRequestExecutorFactory(factory);
  63. appContextSite = new SP.AppContextSite(clientContext, hostweburl);
  64. web = appContextSite.get_web();
  65. clientContext.load(web);
  66. Wingtip.JSOMHostWebCollections.HWReadListData();
  67. }
  68. ReadListData = function()
  69. {
  70. debugger
  71. var oList = web.get_lists().getByTitle("Book");
  72. var camlQuery = new SP.CamlQuery();
  73. camlQuery.set_viewXml('<View><RowLimit></RowLimit>10</View>');
  74. var collListItem = oList.getItems(camlQuery);
  75. //clientContext.load(collListItem);
  76. clientContext.load(collListItem, 'Include(ID,BookName,BookAuthor,BookPrice,BookVersion)');
  77. clientContext.executeQueryAsync(
  78. Function.createDelegate(this, onQuerySucceeded),
  79. Function.createDelegate(this, onQueryFailed)
  80. );
  81. function onQuerySucceeded(sender, args)
  82. {
  83. var innerHtml = "<tr><td class='ListTH'>ID</td><td class='ListTH'>Book Name</td><td class='ListTH'>Book Author</td><td class='ListTH'>Book Price</td><td class='ListTH'>Book Version</td></tr>";
  84. debugger
  85. var listItemInfo = '';
  86. var listItemEnumerator = collListItem.getEnumerator();
  87. while (listItemEnumerator.moveNext())
  88. {
  89. var oListItem = listItemEnumerator.get_current();
  90. var ID = oListItem.get_item('ID');
  91. var InputData1 = oListItem.get_item('BookName');
  92. var InputData2 = oListItem.get_item('BookAuthor');
  93. var InputData3 = oListItem.get_item('BookPrice');
  94. var InputData4 = oListItem.get_item('BookVersion');
  95. innerHtml += "<tr class='ListTR'><td>" + ID + "</td><td>" + InputData1 + "</td><td>" + InputData2 + "</td><td>" + InputData3 + "</td><td>" + InputData4 + "</td></tr>";
  96. //listItemInfo += '\nID: ' + oListItem.get_id() + '\nTitle: ' + oListItem.get_item('Title') + '\nBody: ' + oListItem.get_item('Input1');
  97. }
  98. $("#ListData").html(innerHtml);
  99. //alert(listItemInfo.toString());
  100. }
  101. function onQueryFailed(sender, args)
  102. {
  103. alert('Request failed. ' + args.get_message() +
  104. '\n' + args.get_stackTrace());
  105. }
  106. }
  107. //public interface
  108. return
  109. {
  110. HWLoadlayoutsJS: LoadlayoutsJS,
  111. QSParameter: getQueryStringParameter,
  112. HWLoadClientContext: LoadClientContext,
  113. HWCreateList: CreateList,
  114. HWCreateListItem: CreateListItem,
  115. HWUpdateListItem: UpdateListItem,
  116. HWDeleteListItem: DeleteListItem,
  117. HWClearAllTextBox: ClearAllTextBox,
  118. HWReadListData: ReadListData,
  119. HWEmpty: Empty
  120. }
  121. }();
  122. $(document).ready(function()
  123. {
  124. //Load Out Of Box JS file for List Operation
  125. Wingtip.JSOMHostWebCollections.HWLoadlayoutsJS();
  126. });

Output

Step 3: Add List Item using JavaScript Object model as in the following,

  1. CreateListItem = function()
  2. {
  3. debugger
  4. //var ListNameVal = $(txtExistingListName).val();
  5. var ListNameVal = $(txtListName).val();
  6. if (ListNameVal == "")
  7. {
  8. alert("Please Enter List Name");
  9. return;
  10. }
  11. var list = web.get_lists();
  12. var targetList = list.getByTitle(ListNameVal);
  13. var itemCreateInfo = new SP.ListItemCreationInformation();
  14. oListItem = targetList.addItem(itemCreateInfo);
  15. var Input1Val = $(Input1).val();
  16. var Input2Val = $(Input2).val();
  17. var Input3Val = $(Input3).val();
  18. var Input4Val = $(Input4).val();
  19. var Val1Val = $(Val1).val();
  20. var Val2Val = $(Val2).val();
  21. var Val3Val = $(Val3).val();
  22. var Val4Val = $(Val4).val();
  23. if (Input1Val != "" && Val1Val != "")
  24. oListItem.set_item(Input1Val, Val1Val);
  25. if (Input2Val != "" && Val2Val != "")
  26. oListItem.set_item(Input2Val, Val2Val);
  27. if (Input3Val != "" && Val3Val != "")
  28. oListItem.set_item(Input3Val, Val3Val);
  29. if (Input4Val != "" && Val4Val != "")
  30. oListItem.set_item(Input4Val, Val4Val);
  31. oListItem.update();
  32. clientContext.load(oListItem);
  33. clientContext.executeQueryAsync(
  34. Function.createDelegate(this, CreateListItemSucceeded),
  35. Function.createDelegate(this, CreateListItemFailed)
  36. );
  37. function CreateListItemSucceeded()
  38. {
  39. alert('Item Created Successfully : List Item ID -> ' + oListItem.get_id());
  40. }
  41. function CreateListItemFailed(sender, args)
  42. {
  43. alert('Request failed. ' + args.get_message() +
  44. '\n' + args.get_stackTrace());
  45. }
  46. }

Output



Item Insertion confirmation.


New Record added into list now.

Step 4: Update List item with respect to list item ID value. When you refer UI in order to update list item, we need to provide ID value.

  1. UpdateListItem = function(ListName, Input1, Val1)
  2. {
  3. debugger
  4. //var ListNameVal = $(txUpdationList).val();
  5. var ListNameVal = $(txtListName).val();
  6. if (ListNameVal == "")
  7. {
  8. alert("Please Enter List Name");
  9. return;
  10. }
  11. var Input1Val = $(UpdateField1).val();
  12. var Val1Val = $(UpdateVal1).val();
  13. var list = web.get_lists();
  14. oList = list.getByTitle(ListNameVal);
  15. oListItem = oList.getItemById($(txtUpdateID).val());
  16. oListItem.set_item(Input1Val, Val1Val);
  17. oListItem.update();
  18. clientContext.executeQueryAsync(
  19. Function.createDelegate(this, UpdateListItemSucceeded),
  20. Function.createDelegate(this, UpdateListItemFailed)
  21. );
  22. function UpdateListItemSucceeded()
  23. {
  24. alert('Item Updated Successfully!');
  25. }
  26. function UpdateListItemFailed(sender, args)
  27. {
  28. alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  29. }
  30. }

Output



Item update get confirmation now.

Step 5: Deletion of list item we can use the following code,

  1. DeleteListItem = function(ListName, ItemID)
  2. {
  3. debugger
  4. //var ListNameVal = $(txtListDeletion).val();
  5. var ListNameVal = $(txtListName).val();
  6. if (ListNameVal == "")
  7. {
  8. alert("Please Enter List Name");
  9. return;
  10. }
  11. var Input1Val = $(txtDeletionID).val();
  12. var list = web.get_lists();
  13. oList = list.getByTitle(ListNameVal);
  14. oListItem = oList.getItemById(Input1Val);
  15. oListItem.deleteObject();
  16. clientContext.executeQueryAsync(
  17. Function.createDelegate(this, deleteListItemSucceeded),
  18. Function.createDelegate(this, deleteListItemFailed)
  19. );
  20. function deleteListItemSucceeded()
  21. {
  22. alert('Item Deleted Successfully');
  23. }
  24. function deleteListItemFailed(sender, args)
  25. {
  26. alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  27. }
  28. }

Output


Final Output

Step 6: Style sheet code in order to make UI more effective.

  1. /* Place custom styles below */
  2. .bodyLeft
  3. {
  4. float: left;
  5. padding: 15 px 15 px 10 px 15 px;
  6. border: 1 px solid black;
  7. }
  8. .bodyRight
  9. {
  10. float: left;
  11. padding: 15 px 5 px 5 px 25 px;
  12. }
  13. table
  14. {
  15. border - collapse: collapse;
  16. width: 100 % ;
  17. }
  18. th, td
  19. {
  20. text - align: left;
  21. padding: 8 px;
  22. }
  23. .ListTR
  24. {
  25. background - color: #f2f2f2
  26. }
  27. .ListTH
  28. {
  29. background - color: #4CAF50;
  30. color: white;
  31. }

Step 7: JavaScript complete source code.
  1. var clientContext;
  2. var factory;
  3. var appContextSite;
  4. var web;
  5. var collList;
  6. var itemCreateInfo;
  7. var param1, param2, param3;
  8. var oList, targetList, listFields, oListItem, oField, itemId;
  9. var ExsitingListNameVal;
  10. var targetList;
  11. window.Wingtip = window.Wingtip || {}
  12. Wingtip.JSOMHostWebCollections = function()
  13. {
  14. LoadlayoutsJS = function()
  15. {
  16. //debugger
  17. hostweburl = decodeURIComponent(Wingtip.JSOMHostWebCollections.QSParameter("SPHostUrl"));
  18. appweburl = decodeURIComponent(Wingtip.JSOMHostWebCollections.QSParameter("SPAppWebUrl"));
  19. var Sessionhostweburl = sessionStorage.getItem("hostweburl");
  20. var Sessionappweburl = sessionStorage.getItem("appweburl");
  21. if (Sessionhostweburl == null || Sessionappweburl == null)
  22. {
  23. sessionStorage.setItem("hostweburl", hostweburl);
  24. sessionStorage.setItem("appweburl", appweburl);
  25. }
  26. if (hostweburl == null || appweburl == null || hostweburl == 'undefined' || appweburl == 'undefined') {
  27. hostweburl = sessionStorage.getItem("hostweburl");
  28. appweburl = sessionStorage.getItem("appweburl");
  29. }
  30. var scriptbase = hostweburl + "/_layouts/15/";
  31. $.getScript(scriptbase + "SP.Runtime.js",
  32. function() {
  33. $.getScript(scriptbase + "SP.js",
  34. function() {
  35. $.getScript(scriptbase + "SP.RequestExecutor.js", Wingtip.JSOMHostWebCollections.HWLoadClientContext);
  36. }
  37. );
  38. });
  39. }
  40. getQueryStringParameter = function(paramToRetrieve)
  41. {
  42. //debugger
  43. try {
  44. var params =
  45. document.URL.split("?")[1].split("&");
  46. var strParams = "";
  47. for (var i = 0; i < params.length; i = i + 1)
  48. {
  49. var singleParam = params[i].split("=");
  50. if (singleParam[0] == paramToRetrieve)
  51. return singleParam[1];
  52. }
  53. } catch (ex) {
  54. }
  55. }
  56. LoadClientContext = function()
  57. {
  58. //debugger
  59. clientContext = new SP.ClientContext(appweburl);
  60. factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
  61. clientContext.set_webRequestExecutorFactory(factory);
  62. appContextSite = new SP.AppContextSite(clientContext, hostweburl);
  63. web = appContextSite.get_web();
  64. clientContext.load(web);
  65. Wingtip.JSOMHostWebCollections.HWReadListData();
  66. }
  67. ReadListData = function()
  68. {
  69. debugger
  70. var oList = web.get_lists().getByTitle("Book");
  71. var camlQuery = new SP.CamlQuery();
  72. camlQuery.set_viewXml('<View><RowLimit></RowLimit>10</View>');
  73. var collListItem = oList.getItems(camlQuery);
  74. //clientContext.load(collListItem);
  75. clientContext.load(collListItem, 'Include(ID,BookName,BookAuthor,BookPrice,BookVersion)');
  76. clientContext.executeQueryAsync(
  77. Function.createDelegate(this, onQuerySucceeded),
  78. Function.createDelegate(this, onQueryFailed)
  79. );
  80. function onQuerySucceeded(sender, args)
  81. {
  82. var innerHtml = "<tr><td class='ListTH'>ID</td><td class='ListTH'>Book Name</td><td class='ListTH'>Book Author</td><td class='ListTH'>Book Price</td><td class='ListTH'>Book Version</td></tr>";
  83. debugger
  84. var listItemInfo = '';
  85. var listItemEnumerator = collListItem.getEnumerator();
  86. while (listItemEnumerator.moveNext())
  87. {
  88. var oListItem = listItemEnumerator.get_current();
  89. var ID = oListItem.get_item('ID');
  90. var InputData1 = oListItem.get_item('BookName');
  91. var InputData2 = oListItem.get_item('BookAuthor');
  92. var InputData3 = oListItem.get_item('BookPrice');
  93. var InputData4 = oListItem.get_item('BookVersion');
  94. innerHtml += "<tr class='ListTR'><td>" + ID + "</td><td>" + InputData1 + "</td><td>" + InputData2 + "</td><td>" + InputData3 + "</td><td>" + InputData4 + "</td></tr>";
  95. //listItemInfo += '\nID: ' + oListItem.get_id() + '\nTitle: ' + oListItem.get_item('Title') + '\nBody: ' + oListItem.get_item('Input1');
  96. }
  97. $("#ListData").html(innerHtml);
  98. //alert(listItemInfo.toString());
  99. }
  100. function onQueryFailed(sender, args)
  101. {
  102. alert('Request failed. ' + args.get_message() +
  103. '\n' + args.get_stackTrace());
  104. }
  105. }
  106. CreateList = function()
  107. {
  108. //debugger
  109. var listCreationInfo = new SP.ListCreationInformation();
  110. var ListNameVal = $(txtListName).val();
  111. //var ListNameVal = ListName;
  112. listCreationInfo.set_title(ListNameVal);
  113. listCreationInfo.set_templateType(SP.ListTemplateType.announcements);
  114. oList = web.get_lists().add(listCreationInfo);
  115. clientContext.load(oList);
  116. oList.set_description(ListNameVal + 'created via JSOM Model ...');
  117. oList.update();
  118. clientContext.executeQueryAsync(
  119. Function.createDelegate(this, SPHostWebCreateListSuccessHandler),
  120. Function.createDelegate(this, SPHostWebCreateListErrorHandler)
  121. );
  122. function SPHostWebCreateListSuccessHandler()
  123. {
  124. var result = oList.get_title() + ' List created successfully.';
  125. alert(result);
  126. }
  127. function SPHostWebCreateListErrorHandler(sender, args)
  128. {
  129. alert('Request failed. ' + args.get_message() +
  130. '\n' + args.get_stackTrace());
  131. }
  132. }
  133. CreateListItem = function()
  134. {
  135. debugger
  136. //var ListNameVal = $(txtExistingListName).val();
  137. var ListNameVal = $(txtListName).val();
  138. if (ListNameVal == "") {
  139. alert("Please Enter List Name");
  140. return;
  141. }
  142. var list = web.get_lists();
  143. var targetList = list.getByTitle(ListNameVal);
  144. var itemCreateInfo = new SP.ListItemCreationInformation();
  145. oListItem = targetList.addItem(itemCreateInfo);
  146. var Input1Val = $(Input1).val();
  147. var Input2Val = $(Input2).val();
  148. var Input3Val = $(Input3).val();
  149. var Input4Val = $(Input4).val();
  150. var Val1Val = $(Val1).val();
  151. var Val2Val = $(Val2).val();
  152. var Val3Val = $(Val3).val();
  153. var Val4Val = $(Val4).val();
  154. if (Input1Val != "" && Val1Val != "")
  155. oListItem.set_item(Input1Val, Val1Val);
  156. if (Input2Val != "" && Val2Val != "")
  157. oListItem.set_item(Input2Val, Val2Val);
  158. if (Input3Val != "" && Val3Val != "")
  159. oListItem.set_item(Input3Val, Val3Val);
  160. if (Input4Val != "" && Val4Val != "")
  161. oListItem.set_item(Input4Val, Val4Val);
  162. oListItem.update();
  163. clientContext.load(oListItem);
  164. clientContext.executeQueryAsync(
  165. Function.createDelegate(this, CreateListItemSucceeded),
  166. Function.createDelegate(this, CreateListItemFailed)
  167. );
  168. function CreateListItemSucceeded()
  169. {
  170. alert('Item Created Successfully : List Item ID -> ' + oListItem.get_id());
  171. }
  172. function CreateListItemFailed(sender, args)
  173. {
  174. alert('Request failed. ' + args.get_message() +
  175. '\n' + args.get_stackTrace());
  176. }
  177. }
  178. UpdateListItem = function(ListName, Input1, Val1)
  179. {
  180. debugger
  181. //var ListNameVal = $(txUpdationList).val();
  182. var ListNameVal = $(txtListName).val();
  183. if (ListNameVal == "")
  184. {
  185. alert("Please Enter List Name");
  186. return;
  187. }
  188. var Input1Val = $(UpdateField1).val();
  189. var Val1Val = $(UpdateVal1).val();
  190. var list = web.get_lists();
  191. oList = list.getByTitle(ListNameVal);
  192. oListItem = oList.getItemById($(txtUpdateID).val());
  193. oListItem.set_item(Input1Val, Val1Val);
  194. oListItem.update();
  195. clientContext.executeQueryAsync(
  196. Function.createDelegate(this, UpdateListItemSucceeded),
  197. Function.createDelegate(this, UpdateListItemFailed)
  198. );
  199. function UpdateListItemSucceeded()
  200. {
  201. alert('Item Updated Successfully!');
  202. }
  203. function UpdateListItemFailed(sender, args)
  204. {
  205. alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  206. }
  207. }
  208. DeleteListItem = function(ListName, ItemID)
  209. {
  210. debugger
  211. //var ListNameVal = $(txtListDeletion).val();
  212. var ListNameVal = $(txtListName).val();
  213. if (ListNameVal == "")
  214. {
  215. alert("Please Enter List Name");
  216. return;
  217. }
  218. var Input1Val = $(txtDeletionID).val();
  219. var list = web.get_lists();
  220. oList = list.getByTitle(ListNameVal);
  221. oListItem = oList.getItemById(Input1Val);
  222. oListItem.deleteObject();
  223. clientContext.executeQueryAsync(
  224. Function.createDelegate(this, deleteListItemSucceeded),
  225. Function.createDelegate(this, deleteListItemFailed)
  226. );
  227. function deleteListItemSucceeded()
  228. {
  229. alert('Item Deleted Successfully');
  230. }
  231. function deleteListItemFailed(sender, args)
  232. {
  233. alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  234. }
  235. }
  236. ClearAllTextBox = function()
  237. {
  238. $('input[type=text]').each(function()
  239. {
  240. $(this).val('');
  241. })
  242. }
  243. function Empty()
  244. {
  245. console('Hello');
  246. }
  247. //public interface
  248. return {
  249. HWLoadlayoutsJS: LoadlayoutsJS,
  250. QSParameter: getQueryStringParameter,
  251. HWLoadClientContext: LoadClientContext,
  252. HWCreateList: CreateList,
  253. HWCreateListItem: CreateListItem,
  254. HWUpdateListItem: UpdateListItem,
  255. HWDeleteListItem: DeleteListItem,
  256. HWClearAllTextBox: ClearAllTextBox,
  257. HWReadListData: ReadListData,
  258. HWEmpty: Empty
  259. }
  260. }();
  261. $(document).ready(function()
  262. {
  263. //Load Out Of Box JS file for List Operation
  264. Wingtip.JSOMHostWebCollections.HWLoadlayoutsJS();
  265. });