Guest User

Untitled

a guest
Nov 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <script type="text/javascript">
  2. function AddToCart() {
  3. var context = SP.ClientContext.get_current();
  4. var siteUrl = 'https://keoic.sharepoint.com/sites/ProjectSites/test/';
  5. var clientContext = new SP.ClientContext(siteUrl);
  6. var web = context.get_web();
  7. context.load(web);
  8.  
  9. var sourceId = SP.ListOperation.Selection.getSelectedList();
  10. var source = web.get_lists().getById(sourceId);
  11.  
  12.  
  13. var oList = context.get_web().get_lists().getByTitle('Chart');
  14. context.load(oList);
  15.  
  16. var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
  17. // alert('debut');
  18. for (var i in selectedItems) {
  19. var currentItem = source.getItemById(selectedItems[i].id);
  20. context.load(currentItem);
  21. context.executeQueryAsync(Function.createDelegate(this, test), Function.createDelegate(this, error));
  22. }
  23.  
  24.  
  25. function test(sender, args) {
  26. // alert('test');
  27. var itemCreateInfo = new SP.ListItemCreationInformation();
  28. var oListItem = oList.addItem(itemCreateInfo);
  29. oListItem.set_item('Title', currentItem.get_item('Title'));
  30. oListItem.set_item('Item', currentItem.get_item('Item'));
  31. oListItem.set_item('Product_x0020_Name', currentItem.get_item('Product_x0020_Name'));
  32. oListItem.set_item('Description', currentItem.get_item('Description'));
  33. oListItem.set_item('Price', currentItem.get_item('Price'));
  34. oListItem.set_item('Department', currentItem.get_item('Department'));
  35. oListItem.set_item('Branch', currentItem.get_item('Branch'));
  36.  
  37.  
  38. oListItem.update();
  39. oList.update();
  40. context.executeQueryAsync(success);
  41. // alert('done');
  42. }
  43. function success(sender, args) {
  44. alert('Added to chart!');
  45. // window.location.reload(true);
  46. }
  47.  
  48. function error(sender, args) { alert('error'); } ""
  49. }
  50. </script>
  51. <input name="btnApprove" onclick="AddToCart()" type="button" value="Add To Cart"/>
Add Comment
Please, Sign In to add comment