Thursday, June 24, 2010

Creating custom rollup reports with Date Range filters using Data View Web Part

On a recent MOSS 2007 engagement, we were asked to deliver an accounting report. The report had to aggregate data from multiple form libraries and provide the ability to the user to specify a date range for filtering. This would have been easy to build using a specialized tool like SSRS but not a lot of information is available around filtering rollup data in Data View Web part . This article will describe generating the report using OOB Data View Web part.

As part of this solution, we will learn how to:

  • Use a DataView web part to display data from a list
  • Use multiple data sources to provide an aggregated (roll up ) report
  • Provide the ability to filter results for a specific data range by using SharePoint DateTime controls and Data View parameters.

Let’s start by creating 2 custom lists on your site: SourceList1 and SourceList2.

For this exercise, I will keep the structure simple and create the lists with the following 3 columns:

  1. Title
  2. Approved Date
  3. Amount

  Populate the lists with some dummy values, here is what my lists look like.

Step 1: Using a Data View Web Part in SharePoint Designer to display roll up list data (from multiple lists)

  1. Add a new page to your site.
  2. Open the new page in SPD.
  3. Click on “Click to insert a web part”
  4. From the Top Menu, select Data View –> Insert Data View…
  5. In the Data Source Library on the right pane, click on the drop down next to SourceList1 and select “Link to another Data Source”. (Note: to display data from a single list, select Show Data from the menu) 

    SourceList1 Data Source
  6. Select “Configure Linked Source… and in the Link Data Sources Wizard, select SourceList2. 

    image
  7. Click Next and select Merge on the next screen and Click Finish.
  8. Back in the Data Source Properties, navigate to the General Tab and give the Linked Data Source a Name (For e.g. Merged Source)
  9. The “Merged Source” Data source should show up on the Data Source pane at the bottom. Select “Show Data” from the actions menu for the data source.
  10. Select the columns you want in the report and drop them in the DataFormWebPart on the page.
  11. All the rows from both lists should be displayed. 
  12. Click on the image icon to bring up the Common Data View Tasks. You can make changes to the Data View from here like adding / removing fields, applying a sort or adding filtering. We will revisit the Filter option in the next step. 

    image
  13. Save your page and navigate to it from your browser. You should see your roll-up report from the 2 lists. 

  14. We need to get rid of the time that shows up with the Date as we are only interested in the data part.
  15. Select the field in the Data View Web Part and bring up the Common xsl tasks menu by clicking on the image button. Select “DataTime formatting options…” link and uncheck the “Show Time” check box. 

     

Step 2: Adding Date Range filters to the report using Data View Web Part parameters.

Background: SharePoint provides a lot of ways to sort / filter list data and the same functionality is available in views created with Data View Web part. As you probably noticed in the report, this functionality is not turned on by default. To turn on the filtering capability, bring up the Common Data View Tasks menu and in the Data View Properties, check the checkbox for “Enable sorting and filtering on column headers (basic table layout only)”.

This doesn’t fulfill our requirement though. We need the ability to filter the report based on a user accepted date range. If we wanted to filter the report for a specific value, we could have used one of the OOB filter web parts (For e.g Date Filter, Text Filter or SharePoint List Filter). Here are the filters available OOB in SharePoint.

Let’s see the steps to add the Date Range filtering to the report. We will be using the SharePoint DateTime server control to accept the date value from the user. (Note: We can use the standard HTML text box control as well but using the DateTime server control gives us the nice calendar to select the date from instead of manually typing the date in.)

  1. Switch to Split view in SPD
  2. Locate the DateTimeControl in the toolbox and drag drop the control in the code view before the opening “WebPartPages:WebPartZone” tag. Change to id to StartDateCtl. 
     image
                                                    
  3. Select the Control in the Design view, and set the DateOnly property to true in the Tag Properties pane.
  4. Add another DateTime control and change the name to EndDateCtl and set the DateOnly property to true.
  5. Add a HTML Input (Submit) form control

  6. Save the form and preview. Here is what the form should look like (I used some table layouts here, your form might look a little different) 

  7. Now that we have the Date Range fields created, we just have to wire them up with our Date View Web part.

  8. Before we make the changes to the DataView web part, check the source for the aspx page by selecting “View Source” and locate the DateTime control in the HTML. We need to make a note of the control names; we will need them when we create the parameters. For my form they are set to: 
    ctl00$PlaceHolderMain$StartDateCtl$StartDateCtlDate and
    ctl00$PlaceHolderMain$EndDateCtl$EndDateCtlDate

image_40_690D6C08 

  1. In your SPD, bring up the Common Data View Tasks, click on Parameters… and add 2 new parameters called StartDate and EndDate with parameter source set to Form. Paste the control name in the Form Field text box. 

    image

  2. Add the Filter condition to: ApprovedDate <Greater Than or Equal> StartDate AND ApprovedDate <Less Than or Equal> EndDate 

    image

  3. For a simple string filter, that would be the last step. However the dates work differently. The date control saves the date in mm/dd/yyyy format whereas the xslt filter is expecting the date in YYYY-MM-DDTHH:MM:SS format. (For more information about this issue, check out Andy Lewis’ msdn blog entry here)

  4. Luckily for us, Andy Lewis also provides us with an xsl file (date_templates.xsl) that we can use to convert the date to the correct format. I have also copied the file here in case the referenced blog entry is no longer available. This xsl provides many capabilities including the capability to convert a date to an ISO format (convertCalcDateValue)

  5. Copy the convertCalcDateValue xsl template from the xsl file and paste it before the first xsl:template tag in your page.

  6. Locate the following lines in your code:
    <xsl:variable name="dvt_StyleName">Table</xsl:variable>
    <xsl:variable name="Rows" select="/dsQueryResponse/Rows…

  7. Add the following code between the 2 lines:
    <xsl:variable name="StartDate_ISO">
       <xsl:call-template name="convertCalcDateValue">
       <xsl:with-param name="paramDate" select="$StartDate"/>
       </xsl:call-template>
    </xsl:variable> 
    <xsl:variable name="EndDate_ISO">
       <xsl:call-template name="convertCalcDateValue">
       <xsl:with-param name="paramDate" select="$EndDate"/>
       </xsl:call-template>
    </xsl:variable>
     

    These lines will create 2 new variables StartDate_ISO and EndDate_ISO and save the converted StartDate and EndDate values respectively. Next we have to change the filter condition to use these new variables.

  8. Change the reference in the <xsl:variable name=”Rows” select=”dsQueryResponse/Rows… to StartDate_ISO and EndDate_ISO, so the line looks like:

    <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[number(translate(substring-before(@ApprovedDate,'T'),'-','')) &gt;= number(translate(substring-before($StartDate_ISO,'T'),'-','')) and number(translate(substring-before(@ApprovedDate,'T'),'-','')) &lt;= number(translate(substring-before($EndDate_ISO,'T'),'-',''))]"/>

  9. Save the page and test out your page in the browser. 

Stop the Annoying Beep in VMWare environment

Have you ever used a VMWare image and experienced the annoying beep every time a dialog box is displayed or an error happens. It was driving me nuts for months.

I tried turning off the VM speaker, attach the host sound card to the VM, change configuration settings but nothing seems to stop the beep.

Guess what, there is a simple fix... Go to the command prompt on your VM and type

C:\> net stop beep

If you see the message above, Voila... there goes the Beep!

Have a peaceful (no beep) day !

[Updated…]

FYI, you’ll have to do this every time the VM is rebooted.

A permanent solution is to disable the hidden “Beep” device in device manager.

Right-click “My Computer”/ Properties/ Hardware tab / Device Manager Button / “View” in the toolbar / select “show hidden devices” / expand the “Non-Plug and Play Driver” node / right-click “Beep” and click disable

Unable to remove InfoPath Form Template from Central Admin

Came across another MOSS Gotcha recently. When we tried to remove a form from Central Admin (Application Management Tab --> Manage form templates (under InfoPath Forms Services), form status changed to "deleting". Even after an hour the status was still showing up as deleting.

Here is what I had to do to clean it up.

1. Run the stsadm command to look at the formtemplates on the server

stsadm -o enumformtemplates

This will show you a list of all the formtemplates with their formid (which is important since we will need the formid later.) You should see a row per form with the form name and the form id. (I have highlighted the form id for the first form in red below)

CollectSignatures_Sign_1033.xsn urn:schemas-microsoft-com:office:infopath:workflow:CollectSignatures-Sign:1033

Expiration_Complete_1033.xsn urn:schemas-microsoft-com:office:infopath:workflow:Expiration-Complete:1033

RR_OOB_WrapItUp_1033.xsn urn:schemas-microsoft-com:office:infopath:workflow:OOB-WrapItUp:1033

ReviewRouting_Assoc_1033.xsn urn:schemas-microsoft-com:office:infopath:workflow:ReviewRouting-Assoc:1033

2. Run the stsadm command to remove the form template

stsadm -o removeformtemplate –formid “enter the formid here

This actually failed with the message

A deployment or retraction is already under way for the solution "c840c11c-ca88-70ab-9666-c8518ce3b91d.wsp", and only one deployment or retraction at a time is supported.”

3. Open up your browser and Go to Central Admin --> Operations Tab --> Timer Job Definitions (under Global Configuration)

You should see a Job definition similar to: “Windows SharePoint Services Solution Retraction for "c840c11c-ca88-70ab-9666-c8518ce3b91d.wsp"

Click on the job definition and on the next page, delete this job definition.

4. Now go back to the command line and run the last stsadm command again.

stsadm -o removeformtemplate –formid “enter the formid here

If you see this message “The form template has been successfully initiated for removal from the farm. It may take a few minutes for the operation to complete”, it means everything worked and another timer job was successfully created to remove the form template. You can decide to wait for the job to run or use the next step to force running the job.

5. Run the stsadm command to execute the timer job

stsadm.exe -o exeadmsvcjobs

6. Go back to Central Admin and make sure the form template is no longer listed in the Manage Form Templates page.

 

Copying Windows XP Mode Virtual PC on Windows 7 to a new PC

Recently I was trying to setup a new laptop. I had been using Windows 7 64-bit OS for a while with Windows XP Mode virtual PC to run apps not compatible with the 64-bit OS. (For those of you who haven’t used the Win XP mode, this is a great way to run apps that don’t work on 64-bit Win 7 OS. Check out details here at http://www.microsoft.com/windows/virtual-pc/).

Anyway, I didn’t want to setup and reconfigure the Windows XP Virtual PC again on the new PC but couldn’t find instructions to copy the files over. Since this is a virtual PC, I imagined the process would be as simple as copying the VHD files over but that didn’t work for me.

Here are the steps I had to take to move my Windows XP Mode virtual PC from my old laptop to the new one.

  1. Go to the Virtual PC folder under AppData: “C:\Users\xxxxx\AppData\Local\Microsoft\Windows Virtual PC” (Your path will be different; replace the highlighted username with the appropriate name). If you don’t know the path, just type “AppData'” in the run window and press Ok to go to the AppData folder.

image

  1. Update Options.xml here to include:

<default_vm type="string">Windows XP Mode</default_vm>

<configuration>

<paths>

<defaults>

<configuration type="string">C:\Users\xxxxx\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines\</configuration>

</defaults>

</paths>

</configuration>

clip_image001

  1. On the old machine, go to Start –> Windows Virtual PC –> Windows Virtual PC.
  2. Copy over Windows XP Mode.vmcx file to corresponding location on the new laptop.

image

  1. Copy the "Virtual Machines" Folder under the AppData\Local\Microsoft\Windows Virtual PC\ folder from the old machine.

Note: DO NOT COPY the Virtual Applications folder. It is rebuilt when you start the VPC for the first time.

Wednesday, February 3, 2010

Space in Filename changed to underscore when file is downloaded from SharePoint using IE

Yesterday while doing a demo on versioning in SharePoint, I downloaded a file to my local machine, made some updates and uploaded it back to the site expecting to see a new version. However, I was surprised to see a second file in the library. Attributing this to “user” error, I decided to open the document through word, edit and save back and everything worked fine.

I tried the steps again after the demo and realized when the file is downloaded using the “Send To –> Download a Copy” menu, the spaces in the filename are being converted to underscores by IE. (notice in the screenshot below, the filename has a space but the download dialog box converts it to “_”)

image
image
Note: The file is downloaded properly with spaces in the filename if you right click the file and select “Save Target As…”

As I researched this further, I found this blog post entry by Sadalit Van Buren and several other blog posts that talk about the same issue.

I also found a MS KB article (KB# 952730) where this issue documented. However, as per the KB article this is a IE7 issue. I am using Win 7 and IE 8 but still experience the same behavior so it hasn’t been fixed yet.

I haven’t tried the Hotfix yet but will update this blog once I have a chance to do that.