
A frequent request: have the ID displayed when viewing an individual item, in display form (DispForm.aspx) and edit form (EditForm.aspx). This is for example useful when a team uses the default SharePoint ID as identifier in an Issue Tracking list.
Note: the ID cannot be displayed in NewForm.aspx, simply because the ID doesn’t exist yet when you add a new item.
The answer is easy: the ID is actually already in the browser window, in the URL to be precise:
http://…/Issue%20Tracking/DispForm.aspx?ID=1&Source=…
Right, this is not very user friendly, so we are going to add a short script to grab the ID and display it in the page.
To add a script to DispForm.aspx and EditForm.aspx, we’ll use a well known technique:
- append ?ToolPaneView=2 to the URL to switch to edit mode:
http://…/Issue%20Tracking/DispForm.aspx?ToolPaneView=2
- add a hidden CEWP to the page
Then add one of the two scripts below in the source editor of the CEWP:
To display the ID in the first row:
<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>
To display the ID in the last row:
<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.appendChild(IdRow);
}
_spBodyOnLoadFunctionNames.push("DisplayItemID");
</script>

31 comments
Comments feed for this article
January 19, 2009 at 2:23 pm
DaMiCMS
You can simply create a calculated column with =[ID] as formular. greetz.
January 19, 2009 at 5:39 pm
Peter Allen
DaMiCMS,
At first your solution may seem like the simple solution, but you will find some problems:
- The calculated column will not show up in the EditForm.aspx, since it is not an editable field.
- When you create a new items your ID calculated column will not show up with the ID. This is because the ID is provided after the item is submitted and after the calculated column does its calculations. It is not till you edit the item again that the ID will show up. Christophe pointed this out to me on another item we were working on.
- You end up with two ID columns in your list.
Christophe, thanks for another great solution.
Peter
http://www.bitsofsharepoint.com
January 19, 2009 at 11:17 pm
Christophe
DaMiCMS: you should not use [ID] in a calculated column, it just doesn’t work.
Read about the limitations of calculated columns here:
http://pathtosharepoint.wordpress.com/2008/08/07/calculated-columns/
A workaround to duplicate the ID column is to use a workflow, but it’s heavier, and it won’t look good in the edit form.
January 21, 2009 at 5:03 am
Dynamically Add HTML Element To SharePoint « Microsoft Technology, .Net, BizTalk, Sharepoint & etc.
[...] by ken zheng on January 21, 2009 I have played with the javascript for Item ID in display and edit forms. The interesting part is you can add row into table by [...]
January 21, 2009 at 5:34 pm
larry
Not sure if this will help, Line 13, 14 and 15 need to be on one line. It did not work for me until I put that on one line in sp 2007.
Thanks for the post, great job!
January 21, 2009 at 6:52 pm
Christophe
I have corrected the post. Thanks for catching this Larry!
February 3, 2009 at 2:33 am
Irmalinda
Christophe, just wanna tell you that I followed the instruction and it worked perfectly. This is a valuable feature as my manager was manually creating issue id’s so it could show up on the form (not kidding). Thanks very much for sharing your secret recipes!!
February 19, 2009 at 4:36 pm
Erich O'Donnell
The team that I work on has been looking to display the ID in the form for some time. After finding out that a calculated column wouldn’t work (the hard way), implementing this solution is a great relief! Thanks for posting!
March 10, 2009 at 10:37 pm
hp
I have been looking for this for a long time…Thanks for posting! It works great!
March 13, 2009 at 10:10 am
Anonymous
awesome!
March 18, 2009 at 6:33 pm
Jennifer Lewis
Excellent post and blog, Christophe!
April 1, 2009 at 1:00 pm
ID anzeigen lassen auf Display und Edit Forms « Murratore’s Weblog
[...] http://pathtosharepoint.wordpress.com/2009/01/18/item-id-in-display-and-edit-forms/# [...]
April 1, 2009 at 10:32 pm
Daily Blog Post 04/01/2009 « Murratore’s Weblog
[...] Item ID in display and edit forms « Path to SharePoint [...]
April 9, 2009 at 3:32 pm
Gretchen
Loved this solution. However, is there a way to display just the ID, not Issue ID? I believe these are the same number.
April 28, 2009 at 5:46 pm
Sham
I need to edit an a list item with in an infopath form, opened in a content editor webpart. Is it possible to grab the list item id and open the form at the same time. I am unable to get the id from the url.
May 11, 2009 at 6:35 pm
Peter
Very handy post. Very clean solution.
May 12, 2009 at 4:59 pm
Display the Item ID Number in SharePoint Lists - Make IT Complete
[...] the Item ID Number in SharePoint Lists May.12, 2009 in SharePoint http://pathtosharepoint.wordpress.com/2009/01/18/item-id-in-display-and-edit-forms/ Tags: Item ID [...]
May 20, 2009 at 12:08 pm
lena thomopson
Hi Christophe
I was wondering whether you know how I can display ItemID on my custom asp.net form rendered on the DispForm.aspx via the page view web part?
I have modified the DispForm.aspx and removed the ListForm Web Part and replaced it with a page viewer web part which points to a custom asp.net page. This asp.net page is in the _layouts folder of MOSS. I am having no luck passing the Item ID to the page viewer web part and was hoping that I could achieve something similar to what you described in your article but instead of displaying the item id on the listform web part, i will display it on my custom asp page or anywhere else i can access it.
Any suggestions?
Looking forward to your response
Lena
May 28, 2009 at 7:50 pm
Jeremy
This solution seems overly complicated. The ID is stored as a field in the list item so you can just display that field like all the rest of the fields. The field in my custom display form is simply:
This can be displayed on edit forms as well.
May 28, 2009 at 7:51 pm
Jeremy
Form didn’t show the code. It should be something like this:
xsl:value-of select=”@ID”
May 28, 2009 at 11:50 pm
Christophe
Jeremy, I’d love to see how using xslt you can make it simpler than what is in the post. Could you provide all the steps? Feel free to send me an e-mail: Christophe@PathToSharePoint.com
July 2, 2009 at 2:25 pm
Prasanna
Chris,
I have trying unsuccessfully to do this with calculated columns for quite a while now. Your solution worked perfectly. Thank you very much.
July 8, 2009 at 6:46 pm
Jon
Chris,
Thank you very much. I have been very pleasantly surprised at how much community support is out there for SharePoint! Keep up the good work.
Jon
July 13, 2009 at 1:10 pm
Ben
thanks a ton. This has saved me a few times already!!
July 30, 2009 at 4:42 pm
Ven
Excellent article. It worked for me. Thanks a lot and Hats off
August 7, 2009 at 10:39 am
Dimitri
Thanks a lot! Great article!
I still have 1 question. Hope one of you guys can help me out.
In the Dispform it works like a charm
But in Editform, I have a little problem. The ID is displayed, but I also get the green toolbar at the top of the page with:
“Version: published Status: Published and visible”
“Page – Workflow – Tools – “Save and Stop Editing”
Can I modify the CEWP or the script to avoid this?
Thank you
Dimitri
September 8, 2009 at 4:56 pm
Nancy Forbes
This worked great and solved one of my requests but my users also want the email alerts that they receive to contain the ID field as well. Is there a way to add the ID field to the emails?
September 21, 2009 at 11:45 pm
Brian
Wow, this is the best/fastest/easiest solution BY FAR!
good work.
October 5, 2009 at 6:05 am
Santhosh
Excellent Thanks….
October 6, 2009 at 3:10 pm
Thilo
Your source-code view is wrong. At least in FF 3.5.
October 11, 2009 at 2:32 pm
Christophe
Thilo, could you elaborate? What error do you see? Which list type are you using? And is it working for you in IE?