Custom Web Part for Birthday or Anniversary

Technologies: SharePoint 2007-Online; SharePoint Designer 2010-2013; XSL

Purpose: Provide a means to easily manage a list of Contacts and related metadata pertaining to Birthdays, Anniversaries, Engagement Dates, Opportunity Dates, etc. The people and content related to the current month will display. This provides a long-term low maintenance architected solution for an Office Admin or Office Manager role.

Create Contacts List

Column Name                  Column Type

  • Full Name                        People
  • Birth Month                    Choice
  • Anniversary Month      Choice
  • Anniversary Date          Date/Time

Open SharePoint Designer and perform the following operations

Page Setup

  • create a new ASPX page
  • add an empty data view web part
  • insert the data source list of Contacts

Filter

  • include only those entries from the Contacts list where the Anniversary Month relates to the current month

<xsl:variable name=”Rows” select=”/dsQueryResponse/Rows/Row[@AnnivMonth=number(ddwrt:FormatDateTime(string(ddwrt:Today()),1033,’MM’))]”/>

Sort

  • show the resulting entries in ascending sequence by Last Name

Presentation

  • insert two(2) columns to display (ie; Name, Anniversary Date)
    * these are place holders for now
  • retain the column header of ‘Name’
  • change the column header of ‘Anniversary Date’ to ‘Service Years’

Column Headers

<tr valign=”top”>
  <th class=”ms-vh” nowrap=”nowrap”>Name</th>
  <th class=”ms-vh” nowrap=”nowrap”>Service Years</th>
</tr>

Within the template named ‘dvt_1.rowview’, calculate the years of service which is the difference between ‘Today’ and the Anniversary Date

<xsl:variable name=”yearsOfservice”
select=”round(((number(ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(ddwrt:Today()))))
– number(ddwrt:DateTimeTick(ddwrt:GenDisplayName(string(@AnnivDate))))) div 864000000000)
div 365)”
/>

Column Details

  • display the Contact Name

   <td class=”ms-vb”>
    <xsl:value-of select=”@Title”/>, <xsl:value-of select=”@First_x0020_Name”/>
   </td>

  • display the Years of Service
    * show the actual number of years when the value is not equal to 0

<td class=”ms-vb”>
  <xsl:choose>
    <xsl:when test=”$yearsOfservice != ‘0’”>
 <xsl:value-of select=”$yearsOfservice”/>
    </xsl:when>
    <xsl:otherwise>
 &lt; 1 Hire
    </xsl:otherwise>
  </xsl:choose>
</td>

That’s it. Short and sweet.

Save the Web Part

  • position your cursor in the detail area of the web part, select the Web Part tab and save the file locally

Insert onto your Page

  • edit the page where the web part will display
  • upload the Web Part
  • insert onto the page and configure as needed

Leave me a comment if you need any assistance with your project.

Enjoy every sandwich !

Advertisements
This entry was posted in SharePoint Designer, Web Parts, XSL, Data View Web Part. Bookmark the permalink.

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