Sunday, August 17, 2008

Department Based Workflow

This applies to version 5.3.x but also can be used with the latest Sitecore 6. Imagine a scenario when you have a multisite or a department-based content tree with micro-sites or department sections sharing the same data template definitions. For example, we have the “Articles” section defined in the both “US” and “France” micro-sites. The articles as items have the same set of fields, in other words, these items are created from the same data template. Also, there is an absolute requirement is to have different workflows assigned to different instances of the articles. For example, for the articles created inside of the “France” micro-site, the workflow will consist of three states and have a unique set of workflow actions and possibly different security. For the “US” articles, the whole workflow configuration will be different.

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.