Paul 的个人资料Paul Galvin's SharePoint...日志列表SkyDrive 工具 帮助

日志


11月3日

Comparing Dates in a Data View Web Part to Build a WSS KPI

Note: this was first posted at www.endusersharepoint.com here: http://www.endusersharepoint.com/2009/11/02/comparing-dates-in-a-data-view-web-part-to-build-a-wss-kpi-in-sharepoint/.

This is yet another blog post on comparing dates in XSL in a data view web part in SharePoint.

This is my scenario:

  • I have a custom list.
  • The business purpose of the list is to support the idea of a new employee and his/her tasks to be completed within 7 days of starting the job.
  • They are in a “warning zone” after 4 days if they have not completed these tasks.
  • I want to create a simple dashboard that shows green when they have either completed the task or if they have more than 4 days to complete it.
  • I want the dashboard to show yellow if they are in the warning zone.
  • I want to to show red if they have not completed the task after the due date.

I borrowed from this article at Marc Anderson’s blog (http://mdasblog.wordpress.com/2008/02/19/comparing-dates-in-sharepoint-using-xsl/) to get the comparison logic and this article at www.endusersharepoint.com for the basic ideas behind the dashboard (http://www.endusersharepoint.com/2008/12/09/visual-indicators-for-the-masses-kpis-in-wss/) written by Toni Frankola.

You should read the supporting blogs, but the implementation goes like this:

  1. Create a content type (columns + CT)
  2. Create a custom list and associate it with the content type.
  3. Create a web part page.
  4. Add the custom list to the web part page.
  5. Open up the page in SPD.
  6. Convert the list to a DVWP.
  7. Modify the XSL to generate the dashboard bits.

I have two dates: a warning date and a due date.  To compare the dates, my xsl does the following:

 
  <xsl:choose>
  
    <!-- When both handbook and policy are signed, we are green regardless of dates. -->
    <xsl:when test="@Employee_x0020_Handbook_x003F_ = 1 and @Security_x0020_Policies = 1">
      <img src="/_layouts/images/KPIDefault-0.GIF" alt="No problems"/>
       <a href="/HumanResources/Lists/New Employee Checklist/EditForm.aspx?ID={@ID}&amp;Source=/HumanResources/Shared Documents/New Hire Dashboard.aspx"> [Edit]</a>
    </xsl:when>
 
    <!-- Show amber indicator if we're past the warning date. -->
    <xsl:when test="ddwrt:FormatDateTime(string(ddwrt:Today()), 1033, 'yyyyMMdd') &gt;= ddwrt:FormatDateTime(string(@TaskDueDate), 1033, 'yyyyMMdd')">
      <img src="/_layouts/images/KPIDefault-2.GIF" alt="Overdue"/>
        <a style="border: 0px" href="/HumanResources/Lists/New Employee Checklist/EditForm.aspx?ID={@ID}&amp;Source=/HumanResources/Shared Documents/New Hire Dashboard.aspx"> [Edit]</a>
    </xsl:when>
 
    <!-- Show red indicator if we're passed the due date. -->
    <xsl:when test="ddwrt:FormatDateTime(string(ddwrt:Today()), 1033, 'yyyyMMdd') &gt;= ddwrt:FormatDateTime(string(@Warning_x0020_Date), 1033, 'yyyyMMdd')">
      <img src="/_layouts/images/KPIDefault-1.GIF" alt="Warning"/>        
      <a href="/HumanResources/Lists/New Employee Checklist/EditForm.aspx?ID={@ID}&amp;Source=/HumanResources/Shared Documents/New Hire Dashboard.aspx"> [Edit]</a>
    </xsl:when>
 
    <!-- If we get here, we're earlier than the warning date, so we're green. -->
    <xsl:otherwise>
      <img src="/_layouts/images/KPIDefault-0.GIF" alt="No problems"/>
       <a href="/HumanResources/Lists/New Employee Checklist/EditForm.aspx?ID={@ID}&amp;Source=/HumanResources/Shared Documents/New Hire Dashboard.aspx"> [Edit]</a>
    </xsl:otherwise>
  
  </xsl:choose>

 

A few key points from above:

  • I tried to compare dates without using the ddwrt functionality and got nowhere.  I still don’t understand that.  They dates displayed correctly, but both “>” and “<” comparisons always failed.  In the end, ddwrt came to my rescue (thanks, again, Marc).
  • I’m also displaying an [Edit] link to the item.  I mainly did this so that I could easily test this out.  The link itself may be useful to someone trying to figure it out.
  • This is implemented in SharePoint online and works nicely.
  • The images I reference in the _layouts directory (/_layouts/images/KPI…) are available out of the box in my environment so they are probably available for you as well.

Here’s a screen shot of what it looks like for me:

image

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

评论

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。
GalvinPaul 在此页禁用了评论功能。

引用通告

此日志的引用通告 URL 是:
http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!5026.trak
引用此项的网络日志