Lightswitch Deep Linking and Navigation in SharePoint Dialog Frame

Another one of my strange adventures with Lightswitch has made me look deep inside the navigation framework that Lightswitch uses. I will explain the strange symptoms, the cause I found out and the solution that worked for me.

SYMPTOMS

I have a Lightswitch app connected to SharePoint data. I have several screens, one for each list that is managed from Lightswitch. I want to be able to navigate straight to the screen I want from SharePoint, or to deep-link the screen.

To do so, I made a custom Promoted Links list. I added to this list my LS app deep URLs, such as https://appurl/HTMLClient/default.htm?SPHostUrlaaa&SPAppUrl=bbb&SPChromeColor=ccc#/ScreenName/[unique_number]. The ScreenName parameter is different for each screen, obviously. I also configured each link to open in a SharePoint dialog window.

Strange things happened. While I could open the desired screen by clicking on the promoted link, it would start displaying “Error Loading Page” message and keep a /spinning circle icon alive as if it were waiting for a long-running operation, after every navigation to and back from another screen or popup in the app.

image

These symptoms would disappear if the links were opened without dialogs (in the same tab or another browser tab). They would also disappear if I switched to another screen inside the app using the Lightswitch navigation menu.

CAUSE

I first suspected any custom JS files I added to the application. However, it was not until I used Fiddler tool to investigate the requests my app was doing that I found the answer.

Lightswitch app are Single-Page Applications (SPA). They leverage jQuery Mobile framework for Lightswitch navigation and maintaining app state in the browser. jQuery Mobile has a custom navigation feature that overrides standard browser navigation stack to be able to use Back button to go to the previous screen. In a SPA, there is only one “physical” page (default.htm) and all the further requests are done using AJAX calls to the LS backend services.

Fiddler showed me that the error messages were caused by a 404 HTTP not found response to a unknown page that was something like this: /ScreenName/IsDlg=1.

By opening any URL inside a SharePoint dialog, SharePoint automatically adds IsDlg=1 to the URL. It is used by SharePoint to hide any extra chrome such as navigation and toolbar from being displayed inside a dialog. So, my original URL was now changed to as https://appurl/HTMLClient/default.htm?SPHostUrlaaa&SPAppUrl=bbb&SPChromeColor=ccc#/ScreenName/[unique_number]&IsDlg=1. I could now reproduce the error even without SharePoint dialog, just by adding an extra query string parameter to the LS deep link URL and pasting it in the browser address bar.

Well, jQuery Mobile powered Lightswitch navigation seems to break when trying to parse a screen ID that follows the # sign and then finds another query string parameter such as &IsDlg=1. I tried to move the IsDlg parameter to the left of the screen ID. It worked, and I saw that I had to fix the URL in order for the navigation to work.

SOLUTION

I first thought of rewriting the LS URL by adding a custom HTTP module or a IIS rewrite rules but it sounded too cumbersome. I had to find a simpler mechanism to achieve the opening of a specific LS screen in a SharePoint dialog frame.

Thanks to my colleague Sergio Gallego, I was able to find a solution. I made a copy of the default.html page in LS and called it screen.htm. I then changed the ready() event handler inside the page to check for a query string parameter called “s” (for screen). It would then pass the parameter value as a parameter to the LS msls._run() method. This method takes an optional string parameter that is then used to start the LS app and open the screen with that same name.

I had to rewrite my URLs to the following schema: as https://appurl/HTMLClient/screen.htm?SPHostUrlaaa&SPAppUrl=bbb&SPChromeColor=ccc&s=ScreenName.

Here is the full code of the ready() method in the screen.htm file.

IE8 Passes the Acid2 Test

I downloaded the Beta 1 of Internet Explorer 8 from http://www.microsoft.com/windows/products/winfamily/ie/ie8/default.mspx and I was pleasantly surprised that it passes successfully the hard Acid2 test that tests for web standard compliance. It seems that IE8 has a brand new render engine, although the beta keeps an "Emulate IE7" button, just in case.

Acid2 test for FireFox 2

clip_image002

Acid2 test for IE8 Beta1

clip_image002[4]

Error in PortalCrawl Web Service (0x80042617)

This nasty error is shown in Event Viewer when Office SharePoint Search crawler process can’t process "My Sites" to index the users. The unofficial workaround is to delete the SSP and re-create it again. I’ve found another one:

  • Check that the My Sites site collection is NOT in the root (/) of the Shared Services web application. In my case it was under /mysites
  • Delete that site collection
  • Create a new site collection of the type "My Site host" (in Enterprise tab) in the root path (/) of the Shared Services web application
  • Start a Full Crawl

WSS/MOSS SP1 Released!

Finally, the long-awaited SP1 for WSS 3.0 / MOSS 2007 have been released.

You can find them at Microsoft Downloads page:

ATTENTION!

This is a major update to SharePoint which requires a careful planning (especially when you have a large farm). After the installation you must re-run a PsConfig tool again to deploy the SP.

More technical information:

Guides for planning the update:

How to Test a .NET Application That Uses SMTP

How many times you had to set up a SMTP service just to test that your .NET application sends the e-mail correctly? I found that I can test the actual application (not the SMTP delivery) by using a bogus SMTP server in the config file.

It pretends to be a SMTP server but it "delivers" the messages by leaving them into a folder you specify.

<system.net>
  <mailSettings>
    <smtp from="admin@domain.com" deliveryMethod="SpecifiedPickupDirectory">
      <specifiedPickupDirectory pickupDirectoryLocation="c:MailFolder"/>
    </smtp>
  </mailSettings>
</system.net>

Pause until Date Activity Not Triggered

The last in the list of SharePoint quirks happened to me few days ago.

The Symptoms

You have a SharePoint Designer workflow that has a Pause Workflow action until some future date. The date arrives and the workflow doesn’t wake up.

The First Thought

Timer activities in SharePoint workflows were prone to keep sleeping when rehydrated. A fix was promptly released by Microsoft, available here (as I mentioned in this blog).

The Real Culprit

For some obscure reason the SharePoint timer job that wakes up the sleeping workflows got lost. It was not activated. To check this up, fire the CMD window and type:

stsadm -o getproperty -propertyname "job-worfklow" -url http://MOSS_SERVER_URL

in this case it returned

<Property Exist="No" />

just as I feared.

The Solution

stsadm -o setproperty -propertyname "job-worfklow" -propertyvalue "every 1 minutes between 0 and 59" -url http://MOSS_SERVER_URL

Thanks to:
Paul Galvin’s blog (http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!198.entry)
El Blanco’s blog (http://chrissyblanco.blogspot.com/2007/06/issues-with-delay-activity-in-moss.html)

Upload a Document without Lists.asmx

I was looking for a way to quickly upload some documents into a SharePoint document library, when I stumbled upon this fine helper class by Rohit Puri that accomplishes it using WebDAV protocol.

Actually, I managed to build a complete Windows Forms application that resembles the standard SharePoint "Multiple Upload" control. When it’s finished, I will post the source code here.

Excel Services and External Data Ranges

Excel Services cannot render a workbook that contains external data ranges displayed as a table, as mentioned in the documentation.

I had to display a couple of fields contained in a few database tables, in order to use them as a value to be compared against.

The solution: I connected the table as a PivotTable report, with no grouping. It shows the same numbers, but it can be processed by Excel Services on the SharePoint server side.