views:

117

answers:

1

I have a Discussion Board in a SharePoint site which has an additional column named Category. When a new discussion is created, it prompts for Category, and of course this is by design.

The problem is that when the discussion is replied to, it prompts for the category again.

How can I separate the reply functionality so that the Category is not prompted and the Category is set to that of the discussion under which it resides?

I attempted to edit a copy of NewForm.aspx in SharePoint Designer, but you can only edit which WebPart it is using, not which fields are displayed.

+2  A: 

In a SharePoint Discussion Board, there are two separate content types: Discussion and Message. The Discussion is the folder that represents the entire thread of discussion, while the Message is for each reply item inside that folder.

To make the Category only available for the Discussions, instead of just adding the field to the list, add it specifically to the Discussion content type for that board, and make sure it is not added to the Message content type (remove it if it is).


If you want to actually have the Category field on all replies and have it have the same value as the parent discussion, unfortunately you'll have to be a little tricky and use some event handlers. If you aren't yet familiar with them, read this article for a basic example. You'll need to create an "ItemAdding" or "ItemAdded" event and attach it to the Discussion Board. This event receiver should first check if the item being added is a message or a discussion (item.ContentType.Name.Equals("Message")). Then, retrieve the parent; the ID of the parent of the message is stored in a field with the display name "Parent Folder Id". Retrieve the value of the Category for the parent, and then set the value of the Message's Category to match that. Final step, to make the Category field on the Message Content Type not shown in the Edit Form, you need to flip the "ShowInEditForm" property of that field on that content type on that discussion board to "false". You can accomplish this in the object model with a simple list.ContentTypes["Message"].Fields["Category"].ShowInEditForm = false;, where list is your discussion board instance.

ccomet