Wednesday, November 28, 2012

Open SharePoint 2010 List Items Directly into Edit View

Recently a requirement came across to open items in a list view directly into an edit form.  Out of the box, if a user clicks on a list item they are presented with the default display form.  From there they need to click edit to get into the edit form.  While this is not an unreasonable request, sometimes you want users to just go straight to an edit form.

If you need to do this in SharePoint 2013, please visit this post: Open SharePoint 2013 List Items Directly into Edit View

As you can see above, I have a custom list named Custom List with a few columns.  Clicking the item in the list opens the display form.  Just what you'd expect.  Now let's look at why that happens.  Hovering over the link, we'll see that the URL is http://servername/_layouts/listform.aspx?PageType=4&ListId={E4........".  The key piece here is the "listform.aspx" page and the "PageType" querystring parameter.  If you've worked with these forms in the past, you know they are not called listform.aspx, but rather NewForm.aspx, DispForm.aspx, and EditForm.aspx.  So what is happening is the listform.aspx page is checking these querystring parameters and routing to the appropriate form for your needs at that time.

The PageType enumeration parameter determines what kind of form you get.  In this case type 4, which equals a display form.  We want type 6, which equals an edit form.  You can get all the enumeration values over here at MSDN.

Now let's look at two ways to accomplish this, the brute force way and the elegant way.

Option #1 - Brute Force (jQuery)

Here we will use the tried and true Content Editor Webpart and jQuery.  Sometimes you just don't have access to Designer or Visual Studio for a more robust solution and a little jQuery never hurt anyone!

Simply place a CEWP on your list view page and edit its HTML placing the following inside:

<script type="text/javascript">
$(function() {
  // Change all display form links to edit form links
('.ms-vb a[href*="listform.aspx"]').each(function(){
var link = $(this).attr('href');
= link.replace("PageType=4", "PageType=6");
(this).attr('href', link);

This script is pretty straight forward, it looks for all links within a class of .ms-vb that have listform.aspx in their value.  If you inspect the links on your form you'll see they are wrapped in a DIV with this class applied.  After it finds all of the links it pulls the href value out and performs a replace changing the PageType to 6.  It then sets the link back to this new updated value.

This method works great, although you may have to put this script into an external file and reference it in the CEWP, as they do not like inline scripts sometimes!

Option #2 - Elegant (Custom List View)
Now I love jQuery, and the method above works just fine but I don't really like placing CEWPs on pages to inject scripts like that.  For a more elegant soltuion enter a custom list view and SharePoint Designer.  The nice thing about this solution is its simple and easy, and we can create a new view which will can apply to the list.  This gives a great way to back this change out as well, which is always nice to have as an option.

Before we start, you have to make sure there is at least 1 item in your list!  We'll need this item in Designer to change the link value.

Open Designer and navigate to our Custom List.

In the Views section, click the "New" button.

We'll name this view "All Items With Edit Links" and mark it as the default view.

Now that we have the new view in our Views, click the view to open it in Designer.  Then switch it over to Design view.

Double click the item in the list so that you highlight the actual link that opens the form.  Simply clicking it will activate the TD around it, you need to double click it to activate the link.  You'll know you have when you can see its Tag Properties in the left hand pane, and the first attribute is "href" with a value like "{$FORM_DISPLAY}&ID=....."

In the left hand Tag Properties pane click the value for the "href" attribute, this will activate the link for the XPath Experssion Builder.  Click the "fx" link to launch it.

In the XPath Expression Builder you have a lot of options.  Fortunately for us, we only need to change the value in the "Edit the XPath expression" textbox.  Its current value should be "$FORM_DISPLAY".  We'll change it to "$FORM_EDIT".  This must be in all caps!

Click OK and then click Save in Designer to push the changes to your list.

Now, go back to your SharePoint site and visit the home page.  In my environment I have the Custom List in my Quick Panel.  Refreshing the home page will update that link with the new list view.  Clicking the updated link will take you to your new list view with updated links!

Hovering over the link, it should now look like this: http://servername/_layouts/listform.aspx?PageType=6&ListId={E4........".  Clicking the link will present us with the edit form.

And that's it!  If you need to revert back to the original view, just change it in the List Settings!

As you can see, you have a couple of options to acheive opening edit forms by default.  If you have access to Designer I would definitely go that route.  It provides a cleaner option for making this change and you can avoid some of the headaches that CEWPs and Javascript can present.



  1. I tried the steps above but don't see the "href" with a value like "{$FORM_DISPLAY}&ID= when i double click?

    1. You may not have the actual link selected, from above "Double click the item in the list so that you highlight the actual link that opens the form. Simply clicking it will activate the TD around it, you need to double click it to activate the link."

  2. Thanks a lot for that. It worked like a charm!

  3. This works great on the list directly! Is there anyway to do it as easily on a web part?

    1. Nevermind. I got it to work with the CEWP solution you provided. Thanks!

  4. Does it works with MOSS2007? In my case I don't see any listform.aspx, but directly DispForm.aspx on the link.
    (and my SP Designer 2007 is slightly different from yours, so I think I can't implement the solution).

    1. Sorry, I don't have a 2007 environment to test in so I'm not sure if this will work there or not.

  5. You stated the following:

    "This method works great, although you may have to put this script into an external file and reference it in the CEWP, as they do not like inline scripts sometimes."

    I am tech-illiterate. Do you have a tutorial for how to do this, as I received an error msg when copying the script into CEWP. Thanks!!

  6. Hi, This is great and exactly what I am looking for.. but I need this in SharePoint 2013. Could you please help me to achieve this is SP 2013?

    1. Here you go:

  7. Great post! I am see the programming coding and step by step execute the outputs.I am gather this coding more information. It's helpful for me my friend. Also great blog here with all of the valuable information you have.
    Sharepoint Training in Chennai