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>
You can simply create a calculated column with =[ID] as formular. greetz.
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
DaMiCMS: you should not use [ID] in a calculated column, it just doesn’t work.
Read about the limitations of calculated columns here:
https://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.
Pingback: Dynamically Add HTML Element To SharePoint « Microsoft Technology, .Net, BizTalk, Sharepoint & etc.
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!
I have corrected the post. Thanks for catching this Larry!
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!!
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!
I have been looking for this for a long time…Thanks for posting! It works great!
awesome!
Excellent post and blog, Christophe!
Pingback: ID anzeigen lassen auf Display und Edit Forms « Murratore’s Weblog
Pingback: Daily Blog Post 04/01/2009 « Murratore’s Weblog
Loved this solution. However, is there a way to display just the ID, not Issue ID? I believe these are the same number.
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.
Very handy post. Very clean solution.
Pingback: Display the Item ID Number in SharePoint Lists - Make IT Complete
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
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.
Form didn’t show the code. It should be something like this:
xsl:value-of select=”@ID”
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
Chris,
I have trying unsuccessfully to do this with calculated columns for quite a while now. Your solution worked perfectly. Thank you very much.
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
thanks a ton. This has saved me a few times already!!
Excellent article. It worked for me. Thanks a lot and Hats off
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
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?
Hey Nancy,
Did you ever find a solution to this?
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.
Wow, this is the best/fastest/easiest solution BY FAR!
good work.
Excellent Thanks….
Your source-code view is wrong. At least in FF 3.5.
Thilo, could you elaborate? What error do you see? Which list type are you using? And is it working for you in IE?
DaMiCMS thanks!
The formula solution was the fastest, easiest, no coding, editing or anything!
Thanks for the tip!
CJ_Iceman: what DaMiCMS suggests doesn’t work! Read the replies to his/her comment.
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
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.
Thanks for the solution
Great post! worked like a charm.
Thanks,
Nilesh
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
Nevermind its working. Great solution thank you.
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
Am I supposed to add this script someplace, in order to change the URL?
– append ?ToolPaneView=2
If so, how?
Well, how did you add the script to the display and edit pages?
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?
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.
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?
Nevermind. How terribly silly of me. Forgot to plug in html tags
I am having the same issue as you were having emmanuel. How did you fix it?
Implemented exactly as directed, worked perfectly. Thanks much!!!
Pingback: exibindo o id em uma lista do sharepoint « r. martyres
Pingback: Client side scripts: how will they behave in 2010? « Path to SharePoint
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!
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!
Thank You!
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.
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/
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?
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….
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.
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
Does this work for 2003? Didn’t have much luck.
I wrote it for SP 2007. Unfortunately I don’t have SP 2003 anymore.
I used the calculated field as “=[ID]”. I first had “=ID” but found sometimes the displayed number would show as 0. Dont know why.
“=ID” does not work (see the first comments on this posts).
I love this, so neat! Thank you for sharing Chris 🙂
wow,
This is great.
Thank you very much!
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
Any way to add custom characters in front of the ID?
Also, is ID searchable in SharePoint?
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.
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
What part do you modify to change the displayed name?
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.
Hi Christophe,
First off – great write up – https://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
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.
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.
Thanks for the update Taj. And right, this issue is not directly linked to the script.
Should this work in WSS 2.0???
I’m not having much luck so far!
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!
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!
Nevermind, now it’s working…odd. Anyways, thanks!
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?
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.
Thank you for this tip, been bugging me for a while. I’d found a work around as a calculated column but this is much cleaner. Also opened my eyes to other uses of the CEWP.
Thanks for this – I have just developed a Sharepoint site having been using a Third Party site for some time. The missing ID was always a bugbear and was described as not being possible! This feature will help sell it to my users.
Pingback: My solutions spotted in the blogosphere « Path to SharePoint
Hi,
Great post. I got it working by following the exact guidelines.
However, I came across a problem. Ever since this was added to the page, when a user tries to add an attachment to the item (by updating it), they get an error.
Save Conflict – Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes
I am not sure if this is just coincidence or anything to do with the code. Has anyone else had this issue on a list with this modification?
If so, any solution?
Many thanks,
Anu
Thank you very much, this did the trick.
I added the script so the IssueId shows as the first line. Have no problem with attachments.
Terry
Thanks, this worked as expected.
It worked perfectly for me in the view page. I need more help. How can I send this ID in the ALERT ME functionality email? Please let me know. Thanks
Worked Perfectly for me , clean code and Good work..
Works great in Lists – does not work in Document Libraries. Any suggestions?
Hi,
This post helped resolve my problem and I was able to successfully add the Issue ID to the display and edit forms.
I am not sure if anyone else noticed this but there is a delay in the Issue ID loading. It takes approximate 2 seconds. Is there any way to make the change static and not display after the delay?
Also, I was able to upload an attachment to the item successfully but there is an error when one attempts to delete the attachment from the item.
Error displayed when deleting an attachment:
Save Conflict
Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.
Any ideas/suggestions?
Thanks!
The delay may be due to something loading slowly in your page. Do you have any other customization?
To fix the issue, try this:
– place the CEWP below the form
– replace:
_spBodyOnLoadFunctionNames.push(“DisplayItemID”);
with:
DisplayItemID();
As for the save conflict, sorry, I have no suggestion.
Hey, thank you for the quick solution 🙂
Christophe,
Great solution. Is there a way to force the code so that when a viewer uses the page->send page via-e-mail, the issue ID from the page is included. For some reason the CEWP which displays the Issue ID in the browser – doesn’t pick up the issue ID when it creates the e-mail message.
Try it out and you’ll see.
Is there a way to get this working in a document library?
Add me to the list of people who said, “It’s working now”!
Pingback: Display SharePoint Item ID in List Forms | 3 Guys on SharePoint Blog
Pingback: Showing the Risk or Issue Id’s in the workspace edit and display forms « EPMSource
this is a very good solution and it helped me a lot. Thanks
super solution. works fine. Great help, thanks a lot!
Thorsten
Pingback: Changing editing forms in Sharepoint (2007) « Poco's Blog
Hey guys, does this work for Server 2007?
Yes!
This works great. Thanks for taking the time to figure this out and sharing.
Excellent you are save my time. Thanks aaaaaaaaaaaaa lllllllllllllllllllllllllllllllllllllooooooooooooooooooooooooottttt….
Thanks a lot for the valuable solution…..
this is a great post and has helped me in the past, but is this instruction still relevant? I now see ‘ID’ as a column to add in ‘modify view’ does this replace the need for the hidden CWEP? or am I missing something.
“Modify View” applies to list views, but not to the display and edit forms.
of course! thanks Christophe for clarifying,
I do this exactly you say and it doesn’t work… What happen??
Did you place the script below the form?
Hello ~
Love this workaround. We will be migrating our MOSS portal to SP 2010 next year. My developer raised the possibility that any workarounds could potentially cause javascript errors after migration.
Has anybody used this solution on their lists and then since migrated to SP 2010? If so, did this workaround create any Javascript errors?
Thanks!
It should work as advertised. Your developer is right though, you should be careful with your user managed solutions and include them in your migration tests. I plan to write a blog post on this topic.
Hi, I use Windows SharePoint Services 3.0 and I entered in the display mode and I created a CEWP and then I copied and pasted all the code, but it doesn’t work. What did I do wrong?
Same question as above: Did you place the script below the form?
To entered in edit in the DispForm.aspx, I put ?ToolPaneView=2
at the end of the url like you said in the text. Then I inserted a CEWP that I introduced at the end of the page and inside the CEWP I copied and pasted the script that there is in the text, the same scrypt I didn’t change anything… And it doesn’t work
Finally I could made it works properly, but now I have a new question, when you make a change or something similar and then the system send to you an email, why doesn’t appear the Issue ID in the email??
The script makes a change in the page only, it doesn’t control how e-mails are sent.
Hi:
Could you help me? I having the same issue as others. I have copied and pasted the script as recommended, however I not getting anything. I have read some user have resolve this, but does not explain how. I have programmer skills, so I need a little more detailed information. Thanks.
Pingback: ID in display and edit forms of SharePoint list / library | radhikakasetty
Simple, worked great! Thank you very much.
Hey, just used this to please some users, thank you.
Cant get it to work, added the script at the end of the form but nothing happens. Do I have to change anything in the script?
Hi Chistophe,
Great solution! And it works great on lists. But I’ve tried it on a document library, but can’t get it working.
My lack of knowledge on coding makes it a bit difficult, but I think I know what the problem is. In the script the DisplayItemID function is called, where in a document library items are documents.
Can you maybe help me out on this one?! Any help is greatly appreciated.
Many thanks in advance!
All the best,
Quincy Thomas
Awesome men!
I would expect the script to work on document libraries too, but I haven’t tried. Usually the id is useful for list items, while for documents people are more interested in the name.
Was able to get this to work on the edit form once I swapped _spBodyOnLoad with a DisplayItemID(), but not on the display form. I am using the same method for both and inserting the CEWP after the form. Here’s what I used:
//
// 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.insertBefore(IdRow,ItemBody.firstChild);
}
DisplayItemID();
Sorry, I don’t have an explanation. Or do you have a custom display form?
my short version
function DisplayItemID(){
var regex = new RegExp(“[\\?&]”+”ID”+”=([^&#]*)”);
var qs = regex.exec(window.location.href);
var itemId = qs[1];
// your extra row
var rowHtml = ‘CR – ID’ + itemId + ”;
var t = $(“.ms-formtable”).children(‘tbody:first’)
t.html(rowHtml + t.html());
}
DisplayItemID();
I would not call this short… it uses jQuery so you first have to load hundreds of lines of code! It will run slower too.
Yeah I get it already, She’s fasnttaic. and she certainly is but could you please post some of the races she’s won or her trophy (& medal) collection. Can you show her some respect for all the training she’s been doing instead of just ooogeling at her? thanks Man, DarrylHarrisburg, PA
my rowHtml was destroyed by this homepage script =) i hope this time it works…
var rowHtml = “CR – ID’ + itemId + ‘”;
did not work… :):)
just enter your row html with the td class “ms-formlabel” and “ms-formbody”
Yo, that’s what’s up truthfully.
Thanks a lot
Hi,
Does this work on items that display in a dialog?
I’m clueless at coding, but was able to create the hidden CEWP, all that happened was clicking on the link to the item wouldn’t do anything. Once I removed the CEWP then the links started working again, opening items in a dialog.
Do I need to turn off display forms in a dialog? Or can this be tweaked to work for a dialog?
Thanks in advance
This should work in dialogs. Just make sure you add the code to the dispform.aspx page (dialog target), not the page you open the dialog from.
Hi there,
I’m using SharePoint 2010 and I’ve tried adding this javascript to the Default Display Form and Default Edit Form of my Task list. Initially, everything looked like it worked great, until I went back into the Default Display Form and Default Edit Form to edit them again and I get a javascript error with “Message: ‘1’ is null or not an object”. I’m unable to do anything on the forms, all of the functions in the ribbon are unusable as well, until I delete the CEWP that contains this javascript. Any ideas?
Thanks
Andrea
Well, I have no idea why the code wouldn’t work in your case.
As for removing the CEWP, did you use the ?contents=1 trick?
I am using Sharepoint 2010 (365) and i have the exact same problem 😦
Issue ID is showing though which is great, thanks.
mine is not working. the problem is in the script and creating a row. ID number is still not taken, because when you create a line, it is not known and it is not in the URL
Hi Chris,
Thanks for the great post.
But im facing a small problem.
While the script works like a charm for default display form(dispform.aspx),it doesnt work for custom display forms.
I have a custom display form (display.aspx), but the script doesnt seems to work there.
Any ideas
Thanks
Sanju
The script works for forms that follow the SharePoint out of the box standard. If you go wild with your form layout, then certainly you’ll have to write your own code.
I’ve been surfing online more than 3 hours today, yet I never found any interesting article like yours. It’s
pretty worth enough for me. In my opinion,
if all web owners and bloggers made good content as you did, the web
will be a lot more useful than ever before.
What kind of permissions do I need for this?
Can I do this as Site admin?
THANKS for the code to make this work. I ran into problems when editing the display & edit forms: the ID is not present when the code runs, and browser complains. Here is my version of your cool solution to SharePoint 2010’s issue (and here’s hoping that the pasted text looks somewhat readable):
//
// Item ID in DispForm.aspx and EditForm.aspx
// Feedback and questions: Christophe@PathToSharePoint.com
//
function createTableRow( rowLabel, rowValue )
{
var theNewRow = document.createElement(“TR”);
var tdLabel = document.createElement(“TD”);
var tdValue = document.createElement(“TD”);
tdLabel.className = “ms-formlabel”;
tdLabel.innerHTML = “” + rowLabel + “”;
tdValue.className = “ms-formbody”;
tdValue.innerHTML = rowValue;
theNewRow.appendChild( tdLabel );
theNewRow.appendChild( tdValue );
return theNewRow;
}
function getItemBody()
{
return GetSelectedElement( document.getElementById(“idAttachmentsRow”), “TABLE”).getElementsByTagName( “TBODY” )[0];
}
function insertRowFirst( theRow )
{
var itemBody = getItemBody();
itemBody.insertBefore( theRow, itemBody.firstChild );
}
function appendRowLast( theRow )
{
var itemBody = getItemBody();
itemBody.appendChild( theRow );
}
function DisplayItemID()
{
var idValue = “”;
if ( window.location.href.match(/[\\?&]ID=[0-9]+/) != null )
{
var idValueSlot = 1;
var arrValues = window.location.href.match(/[\\?&]ID=([0-9]+)/);
if ( arrValues.length == 2 )
{
idValue = arrValues[idValueSlot];
}
else
{
alert( “Uh-oh — There are ” + arrValues.length + ” values in the resulting array.” );
}
}
// else
// {
// alert( ‘No ID present.’ );
// }
insertRowFirst( createTableRow(‘Job ID’, idValue) );
// appendRowLast( createTableRow(‘Job ID’, idValue) );
}
_spBodyOnLoadFunctionNames.push(“DisplayItemID”);
This is awesome.
I did not have to alter the code for Sharepoint 2010 and my users LOVE it since they often print object and hand them out to production.
Hey everyone! I do want to ensure you are coming. Get to the Affiliate Circuit Convention this week and find me to talk organization or just straight marketing. I’m flying per day early.
Do not just forget about Mitchells and Jareds shares. And arrived at the Badgerball – I’m going to be there! You could even see me performing some DJing 😉
As a result of most of the affiliate marketing convention and Affiliate Marketing sponsors and I really hope to see you there!
Is it possible to use this code on Sharepoint 2010 task list for the ID column? I added CEWP’s to task list …DispForm.aspx?ToolPaneView=2 and EditForm.aspx?ToolPaneView=2… and copied the code to Content Editor – Editing Tools – HTML – Edit HTML Source, but nothing happened. Did I do something wrong or how I could use this code properly?
To use xslt:
Ticket ID
Sorry -it didn’t show the code I’ll try with commented out:
<!–
Ticket ID
–>
Ok removed all the brackets so you’ll have to add tem back in:
tr
td width=”190px” valign=”top” class=”ms-formlabel”
H3 class=”ms-standardheader”
nobr>Ticket ID /nobr
/H3
/td
td width=”400px” valign=”top” class=”ms-formbody”
xsl:value-of select=”@ID”/
/td
/tr
Just add back opening and closing brackets and change Ticket ID
How to implement this solution on the Info Path display and edit forms?
This is excellent. Thank you. Got it working in Sharepoint 2013.
HI Christophe,
I followed the instructions though it doesn’t show me the ID field when displaying or editing the form.
(MOSS 2007)
I appended the ?toolpaneview=2 to the respective url http://blablalist/dispform.aspx and editform.aspx
In both windows that appeared I added a CEWP with either of the codes.
Unfortenately, when viewing or editing a newly created item in the list, the ID field doesnt appear.
Do you have any advice?
Mark, make sure you put the CEWP below the form.
This is exactly what I need, but I’m a newbie and clueless when it comes to working with code. Can you enter the code in the dispform and editform portions of SharePointDesigner? Do the portions of the code that read TD1.className, TD1.innerHTML, etc. relate to your document or is that global for any document? Can this be used with a Custom List or is it for an Issue Tracking list only? As you can see, any help would be appreciated.
Marty, I’d recommend that you read previous posts to learn more about JavaScript and SharePoint customization. The comments section won’t be enough to explain all of this!
Also, make sure you read the posts that apply to your SharePoint version.