martyychang

Home Page Component: Salesforce CRM Content Updates

Mar 21st, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.24 KB | None | 0 0
  1.  
  2. <table id="contentUpdates" border="1" rules="none" width="100%" bgcolor="#ceecf5" frame="box">
  3.     <thead>
  4.         <tr>
  5.             <th width="10%">Date</th>
  6.             <th width="90%">Resource</th>
  7.         </tr>
  8.     </thead>
  9.     <tbody>
  10.         <tr>
  11.             <!-- Removing lorem ipsum used for styling
  12.            <th>2014-03-20</th>
  13.            <td>069L0000000DC9fIAG &lt;&gt; downloaded</td> -->
  14.         </tr>
  15.     </tbody>
  16. </table>
  17.  
  18. <!-- Execute logic to pull in and render recent content updates -->
  19.  
  20. <script src="/soap/ajax/29.0/connection.js"></script>
  21. <script type="text/javascript">
  22. // Get the session ID from the "sid" cookie
  23.  
  24. var sidRegExp = /sid=([^;]+);/;
  25. var sidMatches = sidRegExp.exec(document.cookie);
  26. var sid = sidMatches[1];
  27.  
  28. // Set the session ID for the Ajax client
  29.  
  30. sforce.connection.sessionId = sid;
  31.  
  32. // Retrieve Content updated in the last 8 days
  33. //var query = 'SELECT Id, Title, CreatedDate, LastModifiedDate FROM ContentDocument WHERE LastModifiedDate = LAST_N_DAYS:8 ORDER BY LastModifiedDate DESC, Title ASC ';
  34.  
  35. var query = 'SELECT Id, Title, LastModifiedDate FROM ContentDocument WHERE LastModifiedDate = LAST_N_DAYS:8 ORDER BY LastModifiedDate DESC, Title ASC ';
  36. var results = sforce.connection.query(query);
  37.  
  38. // Handle the special case where there is only one result, by moving the record
  39. // into an array. When there is more than one result the records are returned
  40. // as an array, but for some reason Salesforce returns a single record as-is,
  41. // instead of putting it inside a 1-element array (at least in API 29.0)
  42.  
  43. if (results.size == 1 && results.records.length == null)
  44.    results.records = [results.records];
  45.  
  46. // Get a reference to the tbody element in which new content updates are going to be displayed
  47.  
  48. var table = document.getElementById("contentUpdates");
  49. var tbody = table.getElementsByTagName("tbody")[0];
  50.  
  51. // Build the rows to present in the table, leveraging knowledge that
  52. // the query results are ordered by LastModifiedDate.
  53.  
  54. var updateDate = null; // Used to determine whether a new row is needed
  55.  
  56. for(var i = 0; i < results.records.length; i++) {
  57.    var doc = results.records[i];
  58.    var docModifiedDate = doc.LastModifiedDate.substring(0, 10);
  59.  
  60.    // We need to create a new row for each new date we encounter.
  61.  
  62.    if(docModifiedDate != updateDate) {
  63.        var tr = document.createElement("tr");
  64.        tbody.appendChild(tr);
  65.        
  66.        var dateHeader = document.createElement("th");
  67.        dateHeader.innerHTML = docModifiedDate;
  68.        tr.appendChild(dateHeader);
  69.  
  70.        var updatesCell = document.createElement("td");
  71.        tr.appendChild(updatesCell);
  72.        updateDate = docModifiedDate;
  73.    }
  74.  
  75.    // Create a link to the document, knowing that the URL should look
  76.    // something like the following:
  77.    // https://na15.salesforce.com/sfc/#version?selectedDocumentId=069i0000000sFDq
  78.  
  79.    var contentURL = "/sfc/#version?selectedDocumentId=" + doc.Id;
  80.  
  81.    var contentLink = document.createElement("a");
  82.    contentLink.innerHTML = doc.Title;
  83.    contentLink.setAttribute("href", contentURL);
  84.  
  85.    updatesCell.appendChild(contentLink)
  86.    updatesCell.appendChild(document.createTextNode(" | "));
  87. }
  88. </script>
Advertisement
Add Comment
Please, Sign In to add comment