Search This Blog

Wednesday, October 6, 2010

How to display the List item ID at the top of the List Item window

Display the List item ID at the top of the List item window.

Category: SharePoint 2010


This is useful when you need to print out a single List item (see how to print a single List item) and share with your team.

Thank you to Christophe@PathToSharePoint.com for the code to display the List Item ID.

a.      Open the List
b.      Hit the List tab
c.      Click the Form Web Parts dropdownlist
d.      Choose “Default Display Form”
e.      At the top of the Page – Insert Tab, Click the Web Part button to add a new Content Editor web part.
f.       From Categories choose “Media and Content” > “Content Editor” and add it to the main section of the page
g.      Click the “Click here to add content” and then click the HTML button in the Ribbon to bring up the Edit source code window.
h.      In the window add the following code to display the Item ID at the top of the list item window.
i.       <code>
<script type="text/javascript">
               //
               // Item ID in DispForm.aspx and EditForm.aspx
               // Feedback and questions: Christophe@PathToSharePoint.com
               //
               function DisplayItemID()
               {
               var regex = new RegExp("[\\?&]"+"ID"+"=([^&#]*)");
               var qs = regex.exec(window.location.href);
               var TD1 = document.createElement("TD");
               TD1.className = "ms-formlabel";
               TD1.innerHTML = "<h3 class='ms-standardheader'>Issue ID</h3>";
               var TD2 = document.createElement("TD");
               TD2.className = "ms-formbody";
               TD2.innerHTML = qs[1];
               var IdRow = document.createElement("TR");
               IdRow.appendChild(TD1);
               IdRow.appendChild(TD2);
               var ItemBody = GetSelectedElement(document.getElementById("idAttachmentsRow"),"TABLE").getElementsByTagName("TBODY")[0];
               ItemBody.insertBefore(IdRow,ItemBody.firstChild);
               }
                
               _spBodyOnLoadFunctionNames.push("DisplayItemID");
               </script></code>
j.      Ignore any Warnings! Next hit the Page tab at the top of the page and view the list item. Done!

Any questions please just ask.

Derek 

No comments:

Post a Comment