I no longer work at Microsoft, so please don't bother leaving a comment here or trying to contact me through my MSDN blog.
You can find my new blog at http://www.technologytoolbox.com/blog/jjameson. My new site also provides copies of all posts from my MSDN blog.
This morning I received an email from a customer inquiring about making it easier for users to determine the unique identifier for each document in a library. Typically, users don't really care about this "List Item ID" for a document, but there are scenarios where this is useful (or perhaps even required).
My initial suggestion was to inform users to obtain the ID from the item properties URL. For example, if you are viewing the properties of a document (http://server/Library/Forms/DispForm.aspx?ID=1956) then you can inspect the URL and determine that 1956 is the ID. Okay, I'll admit, this gets a little cumbersome depending on the URL. For example, it certainly isn't as easy to extract ID 2531 from http://server/sites/foobar/Lists/Work%20Items/EditForm.aspx?ID=2531&Source=http%3A%2F%2Fserver%2Fsites%2Ffoobar%2FLists%2FWork%2520Items%2FOpenItems%2Easpx.
My alternate suggestion -- if the former was deemed unacceptable -- was to display the ID on the item properties page by modifying the item "View" template, similar to changes we had previously made for the "Edit" template in order to render custom field controls. I wasn't wild about this idea, but it was the only other option I could see at the time.
Sure enough, shortly after I clicked Send to respond to the email, a third option occurred to me. How about using a tiny amount of JavaScript to do the work of parsing the URL?
Now, if you have ever worked with me before, you probably know that I hate JavaScript, and it takes some serious motivation to get me to start coding in what I personally consider to be a rather arcane programming language. [No offense to the hundreds of thousands of JavaScript developers out there. If it makes you feel any better, I hate VBScript just as much. It must just be the ex-C++ developer in me that simply can't get over the "loosey-goosey" nature of scripting languages.]
The thought of using JavaScript occurred to me because I recently started using the new Social Bookmarks feature on MSDN, and one of the features of this is a "browser button" (a.k.a. favelet or bookmarklet) that makes it very easy to add the current page as a "social bookmark."
With dreams of a creating a "killer utility for SharePoint", I set out to write a little code to do the work of parsing the ID from various forms of the URL. Here is what I came up with:
Parse List Item ID
With all due credit to the MSDN team, here is some more detail that I snarfed from their FAQ page (with minor modifications, of course):
A browser button (also called a bookmarklet) is an easy way to add bookmarks. The button adds a link to your web browser containing JavaScript. (Don’t worry! This script is safe to include in your browser).
For Internet Explorer users:
For Firefox users: