«

»

May
21
2009

SharePoint fabulous 40: fixing the Board of Directors template

Today I was looking at the Board of Directors template, which is one of the Windows SharePoint Services 3.0 Application Templates (also known as the fabulous 40). This template contains an event calendar for board events. When you add a new board event to that list, a SharePoint Designer workflow creates a new Meeting minutes document. Another workflow adds a new discussion to the discussion board. The display form of the board event contains a number of DataForm web parts that show the content related to the board event, as is shown in the screenshot below:

image

The list of discussion items shows the discussion item created by the SharePoint Designer “Create Discusion” workflow. The link however points to the details page (dispform.aspx) of the discussion item, instead of the page that shows the thread (flat.aspx or thread.aspx). Another problem is that this view always show 0 replies. This is because the discussion item is created using the “Create List Item” activity in the workflow. This way an item is added to the discussion board, but it is not a discussion. You can see that by navigating to the list and opening the item from the summary view. You are now also redirected to the dispform.aspx page and if you reply to the discussion, replies are added to the list as new items, instead of as a reply to the initial item. The screenshot below shows the issues:

image

The idea of the workflow that creates a discussion item for every board event is nice, but it does not work properly. There are 2 ways to fix this. The nicest way is to create a new activity for SharePoint Designer workflows that creates a new discussion item and use that in de workflow. This blog post by Ricardo Costa shows how to do that. Another option is to create a workflow in Visual Studio that creates a new discussion item using SPUtility.CreateNewDiscussion. Then you replace the out of the box Create Discussion workflow in your template. In both cases you will need to create the discussion item and link that to the meeting event (using the Meeting lookup field). Here is the code how to do that:

foreach (SPList list in workflowProperties.Web.Lists)
{
    // Check if this list is a discussion board.
    if (list.BaseTemplate == SPListTemplateType.DiscussionBoard)
    {
        // Start a new discussion on the title of the event.
        SPListItem newDiscussion = SPUtility.CreateNewDiscussion(list.Items, workflowProperties.Item.Title);

        // Update the lookup field to the event, if the field is available.
        if (list.Fields.ContainsField("Meeting"))
        {
            newDiscussion["Meeting"] = workflowProperties.Item.ID;
        }

        // Update the discussion item.
        newDiscussion.Update();

        // Just add a new discussion thread to the first discussion board found.
        break;
    }
}

Last thing you will need to do is to fix the link in the dataview web part. Instead of dispform.aspx, the item needs to point to either the flat.aspx or the threaded.aspx page. Open the dispform.aspx page of the Calendar list.

Search in the XSLT of the Discussion web part for the <td> that renders the hyperlink to the dispform.aspx page using the ID of the item. Replace that <a> with this code:

<a href="../../Lists/Team%20Discussion/Threaded.aspx?RootFolder=Lists%2FTeam%20Discussion%2F{@Title}"><xsl:value-of select="@Title" /></a>

That’s it, now the discussion board in the Board of Directors template works as it should.

Permanent link to this article: http://www.tonstegeman.com/blog/2009/05/sharepoint-fabulous-40-fixing-the-board-of-directors-template/

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>