
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>

81 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?
January 26, 2010 at 12:04 am
Kelly
Hey Nancy,
Did you ever find a solution to this?
January 26, 2010 at 3:36 pm
Nancy Forbes
Not to the email that is generated using the Advanced Settings for the list. However, you can use SharePoint Designer to create a workflow and that workflow can contain any field you want.
We however, recreated our list using the issue log template. (originally it was migrated from 2003) Now the email that gets sent upon ownership change or when the item is changed contains what was changed in the email. Our people like this better and are not as concerned about the ID field showing. It is in the link in the url that is in the email if they hover over it they can get it.
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?
December 3, 2009 at 7:34 pm
CJ_Iceman
DaMiCMS thanks!
The formula solution was the fastest, easiest, no coding, editing or anything!
Thanks for the tip!
December 8, 2009 at 6:08 am
Christophe
CJ_Iceman: what DaMiCMS suggests doesn’t work! Read the replies to his/her comment.
December 5, 2009 at 11:43 am
Shahab
Hi Christophe and many thanks for your helpful article
I just have one more question , could i fill one of my “date/time” fields (say “issue Date/time”) in my custom list ? SharePoint could handle “date” portion with default value, but i really have problem with ‘time’ portion. Could i fill it with jquery in newform.aspx ??
I Really appreciate for your help
December 7, 2009 at 5:22 pm
Sumit
Hi,
Our project requires us to display event title in the calendar grid instead of a . that is generally used in SharePoint 2010. Please suggest if there is a way for us to read event details from a list and then display the same in-line on the grid.
Regards,
Sumit.
January 15, 2010 at 2:55 am
BurnsOil
Thanks for the solution
January 19, 2010 at 10:44 am
Nilesh
Great post! worked like a charm.
Thanks,
Nilesh
January 21, 2010 at 4:10 pm
Robert Plutchak
Christophe,
I have been looking for a solution that does this very thing without using SPD. I have followed the example, however it does not work for me and I was wondering if there is something that could be preventing this from working?
Bob
January 21, 2010 at 8:22 pm
Robert Plutchak
Nevermind its working. Great solution thank you.
January 25, 2010 at 10:37 pm
Stephanie
Hi Christophe,
I copied/pasted the source code you provided into a hidden CEWP & nothing changed in the display or edit modes. Did I miss something? Would really appreciate it if you could help me troubleshoot why it’s not working. Thanks!
Stephanie
January 25, 2010 at 11:04 pm
Stephanie
Am I supposed to add this script someplace, in order to change the URL?
- append ?ToolPaneView=2
If so, how?
January 28, 2010 at 1:19 pm
Christophe
Well, how did you add the script to the display and edit pages?
January 28, 2010 at 6:38 pm
Stephanie
I copy/pasted the script (to have the ID show up in the first row) into a hidden CEWP. But this is the part that I don’t understand what to do:
“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”
I assume this is part of the process that’s needed in order for the other code to work, right?
January 30, 2010 at 4:22 am
Christophe
Well, your hidden CEWP has to be on the DispForm.aspx and EditForm.aspx pages. For example, to add the CEWP to the DispForm.aspx, change the page URL:
DispForm.aspx?ToolPaneView=2
Also, be aware that this change is not supported by Microsoft.
February 8, 2010 at 5:07 pm
emmanuel
Hi Chistophe,
I’ve tried this mod on WSS3.0, however it is only displaying a 01 for all the issues, regardless of their ID. Is there something I need to to do differently to make it work on this version?
February 8, 2010 at 6:00 pm
emmanuel
Nevermind. How terribly silly of me. Forgot to plug in html tags
March 22, 2010 at 9:40 pm
Ali
Implemented exactly as directed, worked perfectly. Thanks much!!!
March 23, 2010 at 12:09 pm
exibindo o id em uma lista do sharepoint « r. martyres
[...] blog path to sharepoint. para mais informações sobre este procedimento, o link direto do post é este aqui. thanks a lot [...]
April 20, 2010 at 1:35 am
Client side scripts: how will they behave in 2010? « Path to SharePoint
[...] 2010, so here too I would expect them to continue working. I only have one script in this category (item ID in display and edit form), and it worked fine in my [...]
May 1, 2010 at 6:16 pm
Addis Abebayehu
I was wandering if you help me with the problem I stuck on. Here it is:
I idea is to have an emal button, next to a close button, on the dispform.aspx. The email button get clicked, it opens up outlook, and attach the list item url in the subject field. Then the user just simply send the data to his or her recipient. How do I accomplish this. I am new and learning. Please help. Thank you!
May 1, 2010 at 6:22 pm
Addis Abebayehu
Sorry, for the typos.
I was wandering if you help me with the problem I stucked on for long time now. Here it is:
The idea is to have an emal button, next to a close button, on the dispform.aspx page. When the email button get clicked, it opens up outlook, and attach the list item url with its specific ID in the subject field of outlook. Then the user just simply send the data to his or her recipient. How do I accomplish this?
Please help. Thank you!
May 5, 2010 at 11:44 am
Rockie
Thank You!
May 7, 2010 at 12:19 am
Kim
thanks for your post. I tested this code in a test area and all worked perfectly. When I implemented in a production area, things went very wrong. Adding the CEWP to the display form worked well. When I added to the editform.aspx, clicking on the link to edit the form, took me back to the list – not the editform.aspx. I followed the instructions in this link and am now able to get to the editform.aspx, although once a user makes changes, they get the following error when trying to commit:
Failed to get value of the “Attachments” column from the “Attachments” field type control. See details in log. Exception message: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)..
At a loss. Working at this since 10 a.m…
Any assistance would be greatly appreciated.
May 7, 2010 at 12:20 am
Kim
forgot to provide the link to the fix for the broken links problem
http://chanakyajayabalan.wordpress.com/2009/11/16/fixing-broken-links-in-sharepoint-list-forms/
May 7, 2010 at 8:47 am
Christophe
So it seems that you used SharePoint Designer to modify the page. Any reason why you did this, rather than using the tip mentioned in the post?
May 7, 2010 at 9:57 am
Kim
I used the tip mentioned in the post, and it worked beautifully on a test area. When I made the same change in a production area, the dispform.aspx worked , but once you clicked on the “edit” button, you were moved to the allitems.aspx page. This page had been edited with Designer in the past. Doing some research, I came across the “fixing broken links in sharepoint list forms” post, and followed the changes described there. Got my edit page to load after making these changes, but, once you do make an edit, and try to commit that change, you get the error I described above. I’m at the point where I just want to be able to create a new editform.aspx. I’ve deleted the cewp from the dispform.aspx thinking that may have been the problem, still not resovled. Not sure where to go from here. Appreciate any help you can give me. This is a corporate app, and we’re now into 24 hours without it. I’m starting to sweat just a little….
May 7, 2010 at 10:45 am
Christophe
Sorry, there’s not much I can do here except confirm – as you found out – that the issue is not with the CEWP or my script.
As your issue is not directly related to this post, I’d suggest to take your question to a SharePoint forum (like STP) where you might get more advice.
May 7, 2010 at 10:52 am
Kim
thank you… I resolved it just minutes ago by following the instructions in this post:
http://jeffreypaarhuis.wordpress.com/2009/06/23/custom-listview-with-attachments/
You can remove my post from this blog now if you wish.
Appreciate you getting back to me.
Kim
May 17, 2010 at 5:35 pm
Robert Sandoval
Does this work for 2003? Didn’t have much luck.
June 4, 2010 at 3:58 am
Christophe
I wrote it for SP 2007. Unfortunately I don’t have SP 2003 anymore.
May 17, 2010 at 11:25 pm
Anonymous
I used the calculated field as “=[ID]“. I first had “=ID” but found sometimes the displayed number would show as 0. Dont know why.
June 4, 2010 at 3:59 am
Christophe
“=ID” does not work (see the first comments on this posts).
May 18, 2010 at 4:47 am
mrhassell
I love this, so neat! Thank you for sharing Chris
May 18, 2010 at 11:30 pm
kingkong
wow,
This is great.
Thank you very much!
May 19, 2010 at 10:49 am
Albert
I try to add this into my disp page but seems it doesnt show the ID and throw a javascript error -
Experts please help!
Albert
May 19, 2010 at 12:48 pm
Tyler
Any way to add custom characters in front of the ID?
Also, is ID searchable in SharePoint?
May 21, 2010 at 1:58 pm
Tom
I was just about to create the same thing… and then did a quick google search and your solution pop’d up.
Thanks for publishing this! It saved me an hour or two and my finished attempted would not have been as slick!
Excellent job.
July 1, 2010 at 1:13 pm
Chinmay
Awesome man.. nice thought process to get the solution.
Works exactly as desired.
I can also change the Column name to be displayed just by modifying the javascript.. COOOOOOOL!!
Thanks mate, cheers
July 13, 2010 at 11:46 am
Alan
Just to say thanks for this code. I have implemented it and its working really well.
Thanks again for fixing a problem I’ve had for a while!
Al.
July 27, 2010 at 7:56 pm
Taj
Hi Christophe,
First off – great write up – http://blog.pathtosharepoint.com/2009/01/18/item-id-in-display-and-edit-forms/
Quick question – one another reader seems to have the same problem – Dimitri
In the Dispform it works like a charm. But in Editform, I have a little problem. The ID is displayed, but I also get a 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?
If I remove this web part – the toolbar does not appear.
Also If I append &PagePreview=true to the URL, the toolbar does not appear. Is there a way to modify the script to either remove the toolbar or add this extra param to the URL.
Thanks for the help.
Gracias,
Taj
July 27, 2010 at 8:14 pm
Taj
This happens irrespective of the script. So even if the script is blank the tool bar appears in the Edit Form. The toolbar is not very annoying, but along with it the form elements have repetitive headings just above the fields.
So say, there is a text box. The text box gets encapsulated by a light border with the heading of that text box displayed within that border. So you have your headings for each component of the form displayed twice, once in the left column, and once above the component itself.
July 27, 2010 at 9:45 pm
Taj
This looks like a bug in SP2 – not sure –
http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/e10ad027-c28a-43ab-8b48-bb02dc3ca782
If you disable publishing the problem disappears. It looks like when you add a webpart to the edit form – something in published view kicks off, so if publishing is disabled, this problem does not occur.
July 29, 2010 at 1:26 am
Christophe
Thanks for the update Taj. And right, this issue is not directly linked to the script.
August 3, 2010 at 9:47 am
Anon
Should this work in WSS 2.0???
I’m not having much luck so far!
August 4, 2010 at 4:00 pm
CJ
I tried putting this into a hidden CEWP, but it won’t display anything! I put the following code into the CEWP:
//
// 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 = “Issue ID”;
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”);
it doesn’t display anything, any advice? Thanks!
August 4, 2010 at 4:01 pm
CJ
Sorry I mean I put that script with the html and body tags as well, still won’t do anything. Any help would be great, thanks!
August 4, 2010 at 5:08 pm
CJ
Nevermind, now it’s working…odd. Anyways, thanks!
August 24, 2010 at 6:51 pm
Ricky
Hi There,
I am working on SharePoint 2010 and the scripts work except for the fact that there is no source editor in 2010 and you have to edit the HTML file. It works fine but after it is done, it won’t let me edit any other web part. Infact, IE gives me the following error:
“Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)
Timestamp: Tue, 24 Aug 2010 18:49:32 UTC
Message: ’1′ is null or not an object
Line: 811
Char: 1
Code: 0
URI: My site
”
Any ideas?
August 25, 2010 at 2:47 am
Christophe
Ricky, the post was written for SP 2007, so I’ll need to do some testing in the new version.
You don’t need the source editor. Store the code in a separate text file, then use the “Content link” of the CEWP to link to it.