Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. function loadContentControls() {
  2. Word.run(function (context) {
  3. var contentControlProperties = [];
  4. var contentControls = context.document.contentControls;
  5. context.load(contentControls, "id");
  6. return context.sync().then(function () {
  7. if (contentControls.items.length > 0) {
  8. for (var x = 0; x < contentControls.items.length; x++) {
  9. contentControls.items[x].load('title,' + "tag");
  10. }
  11. }
  12. else {
  13. $("#notificationBody").html("<h4>No Update Found</h4>");
  14. messageBanner.showBanner();
  15. messageBanner.toggleExpansion();
  16. }
  17. return context.sync().then(function (e) {
  18. for (var x = 0; x < contentControls.items.length; x++) {
  19. contentControlProperties.push({
  20. Name: contentControls.items[x].title,
  21. Moddate: contentControls.items[x].tag,
  22. });
  23. }
  24. return context.sync().then(function () {
  25. var url;
  26. var unParsedDateTime;
  27. var parsedDateTime;
  28. for (var i = 0; i < contentControlProperties.length; i++) {
  29. url = "https://tenant/sites/ContentCenter/_api/web/Lists/GetByTitle('kist')/items?select=Title,Title&$filter=Title eq '" + contentControlProperties[0].Name + "'";
  30. authContext.acquireToken(config.endpoints.SharePoint, function (error, token) {
  31. if (error || !token) {
  32. console.log('error');
  33. return;
  34. }
  35. else {
  36. $.ajax({
  37. type: "GET",
  38. url: url,
  39. headers: {
  40. "Authorization": "Bearer " + token,
  41. "accept": "application/json;odata=verbose"
  42. },
  43. success: function (data) {
  44. unParsedDateTime = new Date(data.d.results[0].Modified);
  45. parsedDateTime = unParsedDateTime.toLocaleDateString('en-US').concat(' ' + unParsedDateTime.getHours() + ':' + unParsedDateTime.getMinutes());
  46.  
  47. >> So if there is a date discrepancy I would like to grab that specific content control here
  48.  
  49. },
  50. error: function (error) {
  51. console.log("Fetching list from SharePoint failed.");
  52. }
  53. })
  54.  
  55. }
  56. });
  57. }
  58. })
  59. })
  60. })
  61. .catch(function (error) {
  62. error.ErrorLocation = "Inserting Content To Doc";
  63. error.ErrorCode = error.debugInfo.errorLocation;
  64. error.ErrorMessage = "Could Not Insert Image";
  65. error.Selection = selectedContents.Name;
  66. ErrorHandler(error);
  67. })
  68. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement