Friday, February 19, 2010

Using [Today] or [Me] in SharePoint calculated columns

One would like to be able to use dynamic information like [Today] or [Me] in calculated columns (for example, to compute "Age" from "DateOfBirth"), but SharePoint complains.

Steve Eagleson was kind enough to point out this article from "Novotronix":

Novotronix Blog - Using [Today] or [Me] in SharePoint calculated columns

which contains a workaround which seems to... um, work.

The workaround involves creating a temporary column called "Today", then creating the formula, then deleting the temp column. This suggests that SharePoint actually knows how to use the dynamic variable, but the parser rejects it when the formula is saved. Very odd...

Tuesday, February 16, 2010

Displaying Attachments to SharePoint Blog Posts

Where I work, we are interested in creating online "learning histories" of our activities.  We conceive of the learning history as a set of brief reflective essays, usually contemporaneous with the events they describe, and sometimes accompanied by (or accompanying) document artifacts. This sort of sounds like a blog with attachments, especially because blogs put chronological organization in the foreground.  

We would like to add entries in the learning history by email as well as via web interface.  So I set up a SharePoint blog, enabled attachments on the "Posts" list, email-enabled the list, and sent an email with attachments.  When viewed via AllItems.aspx, the paper-clip icon was present, but the attachments did not appear when the post was displayed on the Home page or the Post.aspx page.  They did, however, appear on the EditPost.aspx page.  So I knew they were in the system.  [See more information on this in my post "Emailing to SharePoint Blogs".]

I googled and found a post <> that seemed to address the question directly.  The first part of the post deals with changing the site definition of blogs so that "Add Attachment" appears in the "New" and "Edit" page toolbars.  Since I don't have access to the 12 hive for this site, and I know I can get attachments in via email, I skipped to the next step, which reads:

If you want to display the attached files in your post please convert the Web Part in your post.aspx that shows the “post” to an XSLT DVWP.
Fix the Author problem by removing the = character before =@Author and thenfollow the guide below:

Now you have to open the post.aspx of your SharePoint 2007 blog and add the code linked from :

This is a little sketchy, so here is the detail as I experienced it:

The conversion referred to in the first sentence is accomplished in SharePoint Designer.  I started this work by opening the Post.aspx page in SPD, then before doing anything else I saved it under another name (Post-test.aspx).  I did all my testing on this page.  This way, I could test in the live site without interfering with production.

To convert the List View Web part to a Data View (XSLT) Web Part, open the page, select the "Posts" web part (which is displaying "There are no posts in this category."), right-click, and choose "Convert to XSLT".

SPD will complain that it can't display the web part. This is the "Author" problem described by pampigt.  Use the "split" icon to display both the "Design" and "Code" modes, find "=@Author", and change it to "@Author" (there's only one occurrence).   Then save the page — the display will be refreshed.

Then I discovered a problem not described by "pampigt".  I tested the page at this stage, and found that in the browser, it displayed the "There are no posts in this category" message.  Examining the XSLT, it appeared to me that this meant that there were no rows returned by the query.  After much munching around, I found the key to this step:  Using the little arrow-head next to the web part, I opened the Common Data View Tasks menu, and selected "Filter:"  I knew I needed to filter on ID, so I selected that as the field name, and I selected "Equals" as the comparison.  Then, under "Value", I knew I needed value of the query string parameter ID, but that didn't appear in the dropdown.  However, "Create a new parameter..." did appear, so I selected it.  I gave the parameter name "ID" and the source as "Query String".  A few "OK"'s later, I saved the page and tested in the browser.  First Victory!

Now to get the attachments listed on the page.  For this, I used the code linked by "pampigt" from Dario Martirani <>.  His Data View Web Part (he uses the older name "Data Form Web Part") is much simpler than the converted List View Web Part in Posts.aspx, but I took the XSL code for the dvt_1.rowview template and inserted it right above the "Posted at" part of the XSL for my Data View Web part.  I added a test so the code wouldn't be used if there were no attachments, and a <br /> at the end.  Save, test in browser — Second Victory!

Here's the XSL code I ended up with:

   <xsl:if test="@Attachments!='0'">
           <xsl:element name="SharePoint:AttachmentsField">
          <xsl:attribute name="runat">server</xsl:attribute>
          <xsl:attribute name="ListId">
          <xsl:attribute name="FieldName">Attachments</xsl:attribute>
          <xsl:attribute name="ControlMode">Display</xsl:attribute>
          <xsl:attribute name="Visible">true</xsl:attribute>
          <xsl:attribute name="ItemId">
              <xsl:value-of select="@ID"/>
          <br />

Note that, contrary to Dario's post, this appears to work even though the "ListId" attribute is not set to the correct list.  I suppose that the "AttachmentsField" control is getting its context from somewhere other than its attributes...

As the last step, I opened Post.aspx in SPD and saved it as Post-dist.aspx (the version distributed), then put the test page into production by saving it as Post.aspx, so the new version is the target of all the right links.

Remaining issues:   
  1. adding attachment capabilities in the NewPost.aspx and EditPost.aspx pages (without modifying the 12 hive if possible)
  2. adding display of attachments to the blog home page

Emailing to SharePoint Blogs

There are several places to find information on how to "email-enable" a SharePoint 2007 blog -- that is, to make it possible to post to the blog by sending email to it. At my job, I am helping to set up our "Rain King Chronicle" blog to do exactly that, and learned some interesting things about the process, particularly with regard to attachments.

Wednesday, February 10, 2010

Mobile App and OS UI's: A Lot To Learn

Jakob Nielsen has (as usual) some interesting and provocative insights about usability, in this case the usability of iPhone and other mobile apps:
iPhone Apps Need Low Starting Hurdles (Jakob Nielsen's Alertbox)
Nielsen says
The "master guideline" remains the same as in 1986: don't port a UI from an old interface paradigm to a new one.
Nielsen also points out that "on mobile devices, applications are easier to use than websites". Maybe we should look for ways to app-ize our websites for mobile users, rather than make "mobile-friendly" sites that depend on mobile browsers.

On a related note, Slate's Farhad Manjoo says Google's Android OS has a usability issue: "constant menu hunting".
What's Wrong With Android
Manjoo traces the difference between the iPhone user experience and the Android UX to a difference in philosophy:
...Apple is clearly trying to make a complete break with desktop operating systems... under Android's design philosophy, menus are a natural consequence of complexity... That's a familiar view of computing, one deeply tied to the interface on the standard PC...
So Nielsen would probably echo Manjoo's plea to the Android team: "join the menu-free bandwagon!"

And maybe we should rethink our web apps' UX with a more "mobile" mindset.

[On a side note: According to a correction notice on the Slate page linked above, the screenshots of the iPhone and Android calendars had their labels swapped initially. Somehow I doubt that anyone actually believed that the picture from the Android phone was something that ever appeared on an Apple product. Android has more problems than just menu-itis.]
Reblog this post [with Zemanta]