Friday, August 15, 2008

Direct Link to Preview/WebEdit and Workbox

Sometimes it is handy to give out a link to a business users that will lead to a specific mode in Sitecore. For example, you send out an email notification from workflow using email actions <link to sdn5> and would like to control where the users go after the authentication.
Imagine the following email was sent out from Sitecore with a list of links:
Hello Amy,
The item “About Us” was submitted for approval by user “mark” on Aug 15th 2008. Please login to CMS and review the content using one of the following modes:
WebEdit: http://sandbox531071114/sitecore/login/default.aspx?mode=webedit&sc_itemid=%7b3D1814ED-55DD-4518-BD2C-809393F94D2D%7d
Preview: http://sandbox531071114/sitecore/login/default.aspx?mode=preview&sc_itemid=%7b3D1814ED-55DD-4518-BD2C-809393F94D2D%7d
Workbox: http://sandbox531071114/sitecore/login/default.aspx?mode=workbox
Best Regards, Sitecore CMS
Sending out those links is pretty straightforward, while having Sitecore function according to the scenario requires some adjustments.
The first thing that you should do is add a processor to the “login” pipeline that will perform the dynamic switch between the modes by adjusting the LoginArgs’ StartUrl judging by the “mode” query string you pass in the initial URL:
   1: <login argsType="Sitecore.Pipelines.Login.LoginArgs">
   2:     <processor mode="on" type="Sitecore.Pipelines.Login.LoginCookie, Sitecore.Kernel" />
   3:     <processor mode="on" type="Sitecore.Pipelines.Login.Login, Sitecore.Kernel" />
   4:     <processor mode="on" type="Sitecore.Pipelines.Login.Settings, Sitecore.Kernel" />
   5:     <processor mode="on" type="Sitecore.Pipelines.Login.Ticket, Sitecore.Kernel" />
   6:     <processor mode="on" type="Sitecore.Pipelines.Login.CheckStartPage, Sitecore.Kernel" />
   7:     <processor mode="on" type="SCUSAINC.Web.Pipelines.Login.ModeRedirector, SCUSAINC.Web" />
   8: </login>
Depending on the value of the “mode” attribute passed, you can assign one of the following string values:
  • For the Workbox mode - "/sitecore/shell/applications/workbox/workbox.aspx"
  • For the WebEdit mode - "/sitecore/shell/applications/webedit.aspx"
  • For the Preview mode - "/sitecore/shell/applications/preview.aspx"
Since for both WebEdit and Preview you are interested in the redirect to a particular item, you should also pass on the “sc_itemid” query string retrieved from the initial link. So the request will come in to the Sitecore login page with the mode parameter and possibly the sc_itemid parameter as well. After user logs in, the ModeRedirector is called as a last processor and the StartUrl is adjusted accordingly. Then it is all semi-automatic. No matter what mode user selects in the login page options, the query string parameters will always prevail. So if a switch to Workbox occurred, Sitecore will handle this automatically. In case of Preview and WebEdit, the aspx pages do not take advantage of the query string passed to the previous request. In other words, by default, the “sc_itemid” parameter will be neglected. In order to get around this, you can simply override those pages, grab the parameter and pass it on. You can download the package with the solution from here. It contains the code for the ModeRedirector and the overriding code for Preview.aspx and WebEdit.aspx which are located under “/Sitecore/shell/Applications” and also some utility class. I should mention that this was developed on 5.3.1 but with proper adjustments I don’t see any reason why this should not fly on version 6.


Alex said...

The package link seems to be broken.
Any chance you could put it up again?

Alex Shyba said...

Link updated. Please note that this may not work for Sitecore 6.x release.

Kannabiran said...

What is the URL for verion 6.4.1

I have a similar requirement and I need to send a notification mail to content approver and provide Workbox url in the email.

Alex Shyba said...

It's important to note that this solution was created with 5.3.x in mind. If you are on 6.2 and higher, I would frankly use the Client Feeds feature which is a way to get RSS notifications from workflow with links to login. This is a much better way of doing this.