Using content types to modify the NewForm.aspx and EditForm.aspx pages


June 2012 blog post update:
I’ve received quite a few SharePoint 2010 questions regarding this solution, so I’ve added SP2010 setup instructions. For you MOSS 2007 users, don’t worry! The old MOSS setup instructions are still included at the tail end of the post.

When I was at the Best Practices Conference in La Jolla a couple of weeks ago, I taught a session on successfully deploying SharePoint lists. While we looked at a wide variety of tips and tricks and list implementation examples, the attendees were really intrigued by a content type solution I’d implemented to quickly/easily modify NewForm and EditForm ASPX pages. I promised them a blog post on the solution–here it is.

Business scenario:

We use a SharePoint list to store help desk support requests. All SharePoint users have the ability to go to this list and add their support request as a new item. Once they submit their request, the support reps take over ownership of the list item. The support reps have additional information they want to log for each support request (e.g. support rep assigned to the issue, issue resolution, etc.). In order to accommodate, we need to add some “for office use only” fields to our list.

So what are our basic requirements for this solution? We need a streamlined NewForm.aspx page that asks users basic questions about their support request. Once a new item is submitted, we need the item’s EditForm.aspx page to contain additional data fields for the support reps.

Solution:

I could modify my OOB NewForm.aspx and EditForm.aspx pages to achieve these results. This is quite a bit of work, though. Since I want my support reps to be able to manage the fields that display on the NewForm and EditForm pages on an ongoing basis, I’d like a simpler approach that can be managed entirely via the SharePoint web interface. The solution? CONTENT TYPES!

Here’s the basic building blocks of this solution:

  • Setup of 2 new content types (one named “New item” and another named “Existing item”)
  • Setup of a simple SharePoint Designer workflow

We’ll apply 2 content types to my list. We’ll set up “New item” as the default content type that is automatically used when a user clicks on the New button. Next, we’ll set up a SharePoint Designer workflow. This workflow will fire whenever a new item is created in my list. The workflow has a single step with a single action–change the Content Type field from “New item” to “Existing item.” That’s it. When a user creates a new item, the “New item” content type will display a shortened set of fields. As soon as this item is saved, our SharePoint Designer workflow will convert the content type to “Existing item” and the resulting “Existing item” content type fields will display.

Here’s the nitty gritty on how to set this up in SharePoint 2010:

Part 1: Create your new content types.

  1. Click on Site Actions > Site Settings.
  2. Under Galleries, click on Site content types.
  3. Click on the Create button.
  4. In the Name field, type New item.
  5. In the Select parent content type from field, select List Content Types.
  6. In the Parent content type field, select Announcement. Your page should now look like this:
  7. Click OK.
  8. You will be taken to a configuration page for your new content type. Click on the Body field. When the field detail page opens, click Remove. Say OK when you’re prompted to confirm your deletion.
  9. Click on the Expires field. When the field detail page opens, click Remove. Click OK to confirm your deletion.
  10. Click on the Site Settings link in your page’s breadcrumb to return to the main site settings page.
  11. Repeat steps 2-9, this time creating an “Existing item” content type.

Part 2: Add your new content types to your list.

  1. Go to your SharePoint list.
  2. Click on the List subtab and the List Settings icon.
  3. Click on Advanced Settings and set the Allow management of content types field to Yes.
  4. Click OK.
  5. Go to the Content Types section of the page and click on the Add from existing site content types link.
  6. Scroll throught the list of available content types until you find the New item content type you just created. Click on New item and then click on the Add button to move it over to the selection box.
  7. Find and click on Existing item. Click on the Add button to move it over to the selection box.
  8. Click OK. You are now returned to the main list settings page.
  9. Go to the Content Types section of the page and click on the Change new button order and default content type hyperlink.
  10. Uncheck the checkbox for the Item content type and click OK.

Part 3: Configure your content types to display desired fields.

  1. You should still be on your list settings page. Go to the Content Types section and click on your “New item” content type.
  2. Click on the Add from existing site or list columns hyperlink. Add the fields you want to display on your “custom” NewForm.aspx page.
  3. Use the Column order link to define the order in which your fields display.
  4. Click on the List Settings link in your page’s breadcrumb to return to the list settings page.
  5. Repeat steps 1-4 for the “Existing item” content type.

Part 4: Turn “management of content types” off.

Since we don’t want users to see the Content Type field when they are creating or editing list items, we want to turn off the “management of content types” option. Turning this off doesn’t prevent the content types from running–it just prevents the unwanted Content Type field from displaying.

  1. Go to your List Settings page.
  2. Click on Advanced Settings.
  3. Set the Allow management of content types field to No.
  4. Click OK.

Part 5: Create your SharePoint Designer workflow.

This is the last part of this solution. This workflow will automatically detect that a new item has been created and subsequently convert the new item to the existing item content type. Once this is done, the “for office use only” fields will display for the list item.

  1. Open your site in SharePoint Designer.
  2. While on your Site tab, click on the List Workflow dropdown arrow and select your SharePoint list.
  3. When the following dialog box appears, specify a name and (if desired) a description for your new workflow.
  4. Click OK to save your changes.
  5. The workflow builder page will display. Click on the Action button in your ribbon. Then scroll down to the List Actions section and select Set Field in Current Item.
  6. Your workflow will now look like this:
  7. Click on the field hyperlink and select Content Type ID.
  8. Click on the value hyperlink and select Existing item.
  9. Now click on the Workflow Settings button in your toolbar ribbon.
  10. In the Start Options box, check the Start workflow automatically when an item is created option. Next, make sure all other Start Options are unchecked.
  11. Click on the Publish button in your toolbar ribbon to save and publish your new workflow.

That’s it. Now when users create a new item in your list, your SharePoint Designer workflow will automatically reset the new item’s Content Type field from New item to Existing item. This will cause the edit item screen to display a different set of fields for all your existing list items.

Here is our customized NewForm.aspx page:

Here is our customized EditForm.aspx page:

For you MOSS 2007 users, here’s the nitty gritty for setup in 2007:

Part 1: Create your new content types.

  1. Click on Site Actions > Site Settings.
  2. Under Galleries, click on Site content types.
  3. Click on the Create button.
  4. In the Name field, type New item.
  5. In the Select parent content type from field, select List Content Types.
  6. In the Parent content type field, select Announcement.
  7. Click OK.
  8. You will be taken to a configuration page for your new content type. Click on the Body field. When the field detail page opens, click Remove. Say OK when you’re prompted to confirm your deletion.
  9. Click on the Expires field. When the field detail page opens, click Remove. Click OK to confirm your deletion.
  10. Click on the Site Content Type Gallery link in your page’s breadcrumb to return to the main site content type gallery page.
  11. Repeat steps 3-9, this time creating an “Existing item” content type.

Part 2: Add your new content types to your list.

  1. Go to your SharePoint list and click Settings > List Settings.
  2. Click on Advanced Settings and set the Allow management of content types field to Yes.
  3. Click OK.
  4. Go to the Content Types section of the page and click on the Add from existing site content types link.
  5. Find and click on New item. Click on the Add button to move it over to the selection box.
  6. Find and click on Existing item. Click on the Add button to move it over to the selection box.
  7. Click OK. You are now returned to the main list settings page.
  8. Go to the Content Types section of the page and click on the Change new button order and default content type hyperlink.
  9. Change the content type order so your “New item” content type is number 1.
  10. Click OK.

Part 3: Configure your content types to display desired fields.

  1. You should still be on your list settings page. Go to the Content Types section and click on your “New item” content type.
  2. Click on the Add from existing site or list columns hyperlink. Add the fields you want to display on your “custom” NewForm.aspx page.
  3. Use the Column order link to define the order in which your fields display.
  4. Click on the Settings link in your page’s breadcrumb to return to the list settings page.
  5. Repeat steps 1-4 for the “Existing item” content type.

Part 4: Turn “management of content types” off.

Since we don’t want users to see the Content Type field when they are creating or editing list items, we want to turn off the “management of content types” option. Turning this off doesn’t impact the content type display of fields–it just prevents the unwanted Content Type field from displaying.

  1. Go to your list’s settings page.
  2. Click on Advanced Settings.
  3. Set the Allow management of content types field to No.
  4. Click OK.

Part 5: Create your SharePoint Designer workflow.

This is the last part of this solution. This workflow will automatically detect that a new item has been created and subsequently convert the new item to the existing item content type. Once this is done, the “for office use only” fields will display for the list item.

  1. Open your site in SharePoint Designer.
  2. Click on File > New > Workflow.
  3. Specify a name for your new workflow (e.g. “Content type conversion”).
  4. Select your list in the provided dropdown field.
  5. Check the box labeled Automatically start this workflow when a new item is created. Make sure the other 2 checkboxes are not checked.
  6. Click on the Next button.
  7. Click on the Actions button and select Set Field in Current Item.
  8. Click on the field hyperlink and select Content Type.
  9. Click on the value hyperlink and select Existing item.
  10. Click on the Finish button.

That’s it. While this looks like a large number of steps, it only takes about 5 minutes to set up. If you want to re-use this solution multiple times in your site collection, set up your “New item” and “Existing item” content types in your site collection’s content type gallery. This ensures that these content types are available for use in all of the sites within your site collection.

Here is our customized NewForm.aspx page:

Here is our customized EditForm.aspx page:

Advertisements

34 comments

  1. Very cool! I’ve seen very similar stuff before, but the major win is the turn ‘manage content types’ off. That prevents users from being confused and inadvertently changing the value. That was new to me.

    Brilliant solution!

    -Ruven

  2. If you have access to powershell, you could just update the toggles on those fieldrefs for ShowInEditForm and use just one CT.
    I was a little disappointed. It’s a good solution but I was hoping you would be talking about Rendering Templates to customize the list forms.

    1. Like the PowerShell angle, but unfortunately that’s not an option for me. This is more of a “simple and straightforward” solution that works well for end users.

  3. I’ve been trying to find a way to prevent “regular” users from editing their tickets after they are created. Due to some workflow processes, I have to give them Edit permissions. In your solution,
    1. where does the “for office use only” text come from?
    2. what causes “for office use only” to display in some fields for regular users, but not for IT dept. users?
    3. how do I get rid of the “service requests” content type that I have been using because it looks like this is being used for my edit page? When I try to delete it, I get “Error: Content Type is still in use “

  4. Ok, I’ve implemented this solution and verified that “Existing Item” is the content type when editing the ticket, but users can still see and edit all fields. They do not get “for office use only” in any field. Is this because they have Edit permission? I found that I need to give Edit to users because the workflow that runs when item is created does some field updates, i.e. puts Created By into Customer field, sends emails to IT and back to user, etc.

    1. Hi Bob –
      A couple of thoughts:

      1. I used the phrase “for office use only” to describe the business scenario. In my case, I didn’t actually label any of my fields “for office use only.”
      2. In my solution, users aren’t prohibited from going back into an “existing item” and editing any/all fields. The solution is only intended to limit the number of fields displaying on the NewForm.aspx page without having to customize the out of the box form.
      3. You’re right on target with the workflow updates. If a list item update (or creation of a new list item) kicks off a SharePoint Designer workflow, that workflow assumes the permissions of the person who last edited the item. As a result, you cannot remove the user’s edit rights and have a workflow process run and update the list item.
      4. Laura Rogers has a great blog post about using conditional formatting in SharePoint Designer to display SharePoint fields by permission level. Check it out – http://spinsiders.com/laurar/2009/01/23/displaying-sharepoint-fields-by-permission-level/
      1. Thanks for the clarification. The only solution I can think of, since I cannot remove Edit from the users permissions, is to set an audience on the EditForm.aspx page. It’s not an elegant solution, but at least prevents the user from editing or deleting the ticket.

  5. Has anyone tried this solution in SP Designer 2010? I have used this solution successfully in SP 2007, but we have recently upgraded and SP Designer does not seem to be giving me the option to set the condition to Set Content Type to Existing Item. Instead it brings up specific columns or fields in a drop down list rather than allowing me to choose the content type as a whole.

    Has anyone run into this?

  6. Yes! This solution works in SharePoint 2010.

    You don’t need a condition, just an action.

    Choose the Action “Set field in current item”.

    Click on field > select Content Type ID.

    Click on value > Existing Issue.

    Set workflow to start with new item is added.

    Save and Publish.

    Now get yourself a mocha. Your work here is done.

  7. I did follow those steps, but I get an error message of (0, 0) Application configuration file is either missing or does not contain authorizedTypes related configuration information.)

    I also checked my older workflow that was created like this in SP 2007 now that we have converted to SP 2010. The workflow failed to start.

    As far as I can see it doesn’t like the .aspx based form and wants to create it as a .xsn. Does this meant that I will need to tweak my form in InfoPath 2010 and create the workflow there?

    1. Amy –
      I’ve updated the blog post with detailed step-by-steps for SharePoint 2010. I’ve also experimented in a couple of different environments, but haven’t been able to replicate any of the errors you’re seeing. Let me know if the added screen shots and details help!

  8. Sarah – THANK YOU for sharing this!! I’m a newbie and was trying to figure out how to do exactly what you’ve explained. I’m looking forward to getting this to work!

  9. I can get the content type switch to work, I just can’t figure out how to modify my second content type form in InfoPath so I can set specific fields as read only. Any guidance would be appreciated!

    1. Interesting question, Tracy – and something that will no doubt turn into a future blog post. Using content types within a SP2010 list alongside a customized InfoPath form is a bit tricky. By design, any changes you make to your InfoPath form (e.g. field additions) will be written back as changes in your list settings. The changes will only apply to your default content type, however. Let’s say, for example, that you have a custom content type named “New item” set up as the default content type for your list. If you customize your list form via InfoPath, add a new field named “Description,” quick publish your changes and then go back to your list settings, you’ll see that the new “Description” field has been added as a column in your list. But note that the new column is only associated to your default “New item” content type. In order to have that new field apply to all your custom content types you will either need to:

      1. Go into list settings and manually associate your new “Description” field to all other content types.
      2. Switch the ordering of your custom content types so the content type you want to customize is the new default. Then go in and Customize Form and make your changes. By default, those changes will apply to the default content type. Continue switching your defaults as necessary until all changes are made as desired–then go back in and reset to your desired permanent default content type.
      3. Use InfoPath to create forms that can be saved as site content types and deployed via form libraries (an entirely different solution, but something that may be easier to manage if you’re using multiple content types).

      Obviously, your best approach is to get your fields in place (and finalized) before you start making any InfoPath form customizations.

      1. I found an alternative that I thought I would share with you. In the end I do not want my end users to be able select a content type so I was changing the Management of Content to No after I created the content types. When you do this you can only modify the default content type. By turning the Management setting back to yes, you can easily select the form you want to modify. Once it is back to Yes go to List Settings -> Form Settings. Each of your content types are listed there in the drop down and you just need to select the one you want to modify. Once I have my forms updated I go and change Allow management of content types? Back to No.

  10. Having read this I thought it was extremely enlightening.
    I appreciate you spending some time and effort to
    put this informative article together. I once again find
    myself personally spending a lot of time both reading and leaving comments.
    But so what, it was still worth it!

  11. Thank you Sarah – what a useful, informative and mercifully idiot-proof guide!

    I have a slightly different problem. I have a list with a LOT of columns. The owners of the list want just some columns to be edited at different times of the year. They want to know if different editform.aspx forms can be created to make this task simpler for the people inputting the data – i.e. they want different forms to edit the same item.

    I did think that I could create workflows to automatically create new content types when a new item was added to the list, which would then have their own editform.aspx form. But then I think I would also need to create workflows to get these content types to update the original item – and then hide all but the original content type.

    I was hoping there might be a more elegant way to achieve it.

    If you are able to respond it will be great – but thanks for this post anyway – it is great

    1. John –
      You can actually do this a couple of different ways. You could manually create new EditForm.aspx pages in SharePoint Designer and then manually turn them on/off when it’s time to transition. But I’d prefer using the content type option since it is easier for power end-users to configure and manage. The automation of your “switch” date between your content types will be the hardest part to set up. You could set up a manual workflow that you kick off by hand when you’re ready to make each switch, or you could try using hidden date fields and Information Management Policies to automate the switchover of your EditForm.aspx pages. Just set up your Information Management Policies with the “expiration” option. This will enable you to kick off a workflow to change over your content types. Look for a blog post soon with more on Information Management Policies…

      1. Thank you so much for taking the time to make such a considered response Sarah. I really appreciate that. Some great food for thought there. I look forward to your further wisdom on IM policies.

        Thank you again

  12. Wow – this is very cool. Stumbled here looking for an answer to another problem I am having (will bookmark this solution though)! Right now, I cannot seem to get my custom editform webpart to pull in the newform data – it’s defaulting to blank new form (because I copied the webpart code). What do I need to change to get the code on editform to pull in the newform data I want to edit upon selecting edit button?

  13. Sara – Will toggling between each content type allow for “ONE” Content Type Rollup? I have the need to create a document library. After reading your article I was planning on creating a content type for each type of document and displaying only those attributes that apply to the document type that is picked by the user, hiding all the other document type attributes that are not applicable. My thinking is that all fields need to be stored in the document list for one rollup at the root site regardless of what type it is. So what needs to happen is during root site rollup I am actually rolling up the document list across multiple subsites. How do I do that? Does your method accommodate that? Can you create one content type with multiple versions and depending on the version (in my case determined by the document type) have the content type display the appropriate attributes and hide all of the other attributes. I guess I’m thinking as a database person, once all the information is in the doc list, I could use one content type to rollup all the data from the subsites. What do you think?? Thanks, Laura

    1. Laura –
      The content types act like a pick list, displaying just the fields you want to for each content type. If you have 4 content types in a single document library and each content type has 5 unique fields associated with it, you will need all 20 fields/columns set up in your document library. If you wanted to have a content type that showed all 20 fields/columns, you’d just need to create a fifth content type (maybe name it ALL FIELDS) and then associate all 20 fields/columns with this fifth content type.

      1. Sarah, How would you then edit ‘All Fields’ Right now, everytime I click to edit the item- it defaults to ‘EditForm’ in your example. How can you have the option to edit based on content type selection?

    1. If you want to automate the value changes in your Content Type field, you will need SharePoint Designer workflows. If that is not an option in your organization, you will need to rely on your users to manually change the values in the Content Type field. Unfortunately, that does lower the efficiency in solutions like this one.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s