Monday, November 5, 2012

Use HTML in SharePoint Designer to add tables, images and more!

Ever get frustrated that SharePoint Designer doesn't make it easy to add HTML like tables and/or images?

If you click on Advanced Properties on your mail action, and click on Body, you can open it up and edit the HTML directly there.

But there's a catch, if you ever open that back up and edit/save it in the normal UI screen, all of your changes go away!

BUT, if you remove the following tag from that Body property:

<META NAME="Generator" CONTENT="MS Exchange Server version 08.01.0240.003">

your message when viewed via the normal UI will all be HTML, and your changes will be forever saved. 

Friday, September 28, 2012

Merge two lists using a DataView web part

For a survey I created, I needed to merge some user information (e.g. department, Division, etc.) from another list into the survey results, and get those results to display nicely in Excel. A straight DataView data source join got me 80% of the way there, but it was far from ideal, throwing the results of the joined table into a single column at the end of the first table.  I wanted to go one step further and make the html  and the look and feel be ONE table.  So I did the following:

1.  Created a new page and added a DataView web part using SharePoint Designer. 

2.  Followed this article to join my data sources and add all of the fields I wanted:   http://office.microsoft.com/en-us/sharepoint-designer-help/display-data-from-multiple-sources-in-a-single-data-view-HA010099144.aspx 

3.  For each column, move the column titles that get repeated in the joined dataview.  These are held in the dvt_2, 3, 4, etc. templates. 

         <th class="ms-vh" nowrap="nowrap">Department</th>

Paste the columns into the dvt_1 template along with the first table headers: 

           <th class="ms-vh mpi">Department</th>

(I removed the nowrap css since they were survey questions and quite long)

4.  For each column you added, add another column in the dvt_1.rowview template:  
            <td class="ms-vb">
                <xsl:call-template name="dvt_3" />              
            </td>
            .....
           <td class="ms-vb">
                <xsl:call-template name="dvt_9" />                                                                   
            </td>

5.    Immediately after the dvt_2.empty template, copy all the dvt_2 templates and paste it, then change all of the _2 to _3.  Should look like:

<xsl:variable name="dvt_3_automode">0</xsl:variable>
    <xsl:template name="dvt_3">
        <xsl:variable name="dvt_StyleName">Table</xsl:variable>
        <xsl:variable name="dvt_ParentRow" select="current()" />
        <xsl:variable name="Rows" select="../../../Hiring_Manager_Survey/Rows/Row[@Author.title=$dvt_ParentRow/@Title]" />
        <xsl:variable name="dvt_RowCount" select="count($Rows)" />
        <xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0" />
        <xsl:choose>
            <xsl:when test="$dvt_IsEmpty">
                <xsl:call-template name="dvt_3.empty" />
            </xsl:when>
            <xsl:otherwise>
                <table border="0" width="100%" cellpadding="2" cellspacing="0">
                    <xsl:call-template name="dvt_3.body">
                        <xsl:with-param name="Rows" select="$Rows" />
                        <xsl:with-param name="dvt_ParentRow" select="$dvt_ParentRow" />
                    </xsl:call-template>
                </table>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="dvt_3.body">
        <xsl:param name="Rows" />
        <xsl:param name="dvt_ParentRow" />
        <xsl:for-each select="$Rows">
            <xsl:call-template name="dvt_3.rowview" />
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="dvt_3.rowview">
        <tr>
            <xsl:attribute name="class">ms-alternating</xsl:attribute>

            <xsl:if test="$dvt_3_automode = '1'" ddwrt:cf_ignore="1">
                <td class="ms-vb" width="1%" nowrap="nowrap">
                    <span ddwrt:amkeyfield="" ddwrt:amkeyvalue="string($XPath)" ddwrt:ammode="view"></span>
                </td>
            </xsl:if>
            <td class="ms-vb mpi">
                <xsl:value-of select="@On_x0020_a_x0020_scale_x0020_of_2" />
            </td>
           
        </tr></xsl:template>
    <xsl:template name="dvt_3.empty">
    </xsl:template>

6.  Change the <xsl:value-of select="@On_x0020_a_x0020_scale_x0020_of_2" /> to the Internal Name of the field that you want displayed.

7.  Repeat steps 5 and 6 for each column you added.

The end result will be a merged dataview showing the joined results from two separate lists, that users can view or right-click to easily export to Excel:



Monday, August 6, 2012

New handler in an event receiver not updating

When adding a new handler to an already existing event receiver, if deploying via Visual Studio the changes won't get updated.  To get your changes to take, you just need to manually re-activate it's feature via PowerShell with the -Force parameter.

Tuesday, July 17, 2012

SharePoint Designer Workflow: Make a Dynamic Link when Setting a Field Value

I had a scenario where a user would submit a form, a workflow would create a supporting folder in a document library, and I wanted to create a link to that folder in the original list. 

Wanted to document the steps to accomplish it:

1. In your list where you want the link to be displayed, make a new Hyperlink or Picture column.

2.  In your SharePoint Designer workflow, create a Workflow Variable and set it to the following, making sure NOT to include the http:// before your url:

               siteurl/site/[% Dynamic Token %], Link Text to Display

NOTE:  The comma is the separator from what the href value will be and what the text displayed will be.

3.  Set the Field Value in your list to the Workflow Variable.

Tuesday, May 8, 2012

Adding Created By / Author into XSLT

Trying to display the Created By or Date Modified in your XSL transform in something like a DataFormWebPart?  The ol'
<xsl:value-of select="@Author"/>
won't do the trick.  But you can use a custom template in the CreateModifiedInfo control to display what you'd like:
<SharePoint:CreatedModifiedInfo ControlMode="Display" runat="server">
<CustomTemplate>
      Posted By:  <SharePoint:FormField FieldName="Author" runat="server" ControlMode="Display" DisableInputFieldLabel="true" />
</CustomTemplate>
</SharePoint:CreatedModifiedInfo>

Friday, April 20, 2012

XSLT adding values to HTML tags

Two techniques for adding a value to an HTML tag:

1.  Shorthand:  <img src="{@Image}" />   

2. Longhand:

<img>
   <xsl:attribute name="src">
       <xsl:value-of select="@Image"/>
   </xsl:attribute>
</img>
                               
                              

SharePoint Designer 2010 Workflow changes not taking effect

Was making changes to a workflow in SharePoint 2010 and none of my changes seemed to be taking hold when I published my workflow.  I came across this thread:

http://social.technet.microsoft.com/Forums/en/sharepoint2010customization/thread/a1034c24-809c-4c00-b57b-f43ea6171981

and it solved my problem.  I had to delete the files in my \local settings\app data\msft\websitecache and \app data\msft\sharepoint designer\proxyassemblycache folders.  This cleared things out and my updates were now being seen.

Remoted Desktop cut/paste stops working

If you're logged into a remote desktop session and your cut and paste functionality stops working, you can resuscitate it by doing the following:
  1. Open up task manager.
  2. Select the "rdpclip" process and click End Process
  3. Go to Start -> Run and type in "rdpclip" and you should be all set.

Delete a column in a list missing a delete button

For sealed columns (e.g. Rollup Image, etc.), there's no way to delete them from the UI.  But you can easily get around this if you use the following powershell command:

$web = Get-SPWeb -identity http://site/name/
$list = $web.Lists["ListName"]
$column = $list.Fields["Rollup Image"]
$column.Sealed = $false

Then that Delete button will be visible and you can go ahead and delete that column.

Thursday, April 19, 2012

Get the XML feeding your XSLT

Got this little tidbit from Joe Picc today, which is a good way to get the XML that's getting passed to your XSLT in your SharePoint web parts:

After your  <xsl:template match="/" ...> tag, add the following:

                <xmp>
                      <xsl:copy-of select="." />
               </xmp>

What gets returned is the XML that is sent to your XSLT, so if you need to check it out or debug with it you can.