Question

I’m stuck with a little development annoyance. I have crated an application to extend Sitecore authoring interface. The application queries some internal services and asks few additional questions from a content author before creating an new content item in Sitecore. I have modeled the app on (Sitecore.Shell.Applications.Templates.CreateTemplate.CreateTemplateForm).

The problem I’m having is, as soon as an item is created my WizardForm is reloaded to load newly created item. What I want is for the wizard to go through to the “Final” page and reload the main UI once the modal dialog is closed. Exactly how new OOTB template wizard works. I know that if I comment my item creation code out the UI behaves as expected. Looks like a create of an item generates some events in the background that UI is responding to and reloads my modal dialog with the newly created item. (I have tried the following solutions http://sdn.sitecore.net/Forum/ShowPost.aspx?postid=29092, http://sdn.sitecore.net/Forum/ShowPost.aspx?postid=29968, however this does not seem to solve it for me).

The original code seems to disable events like so:

        this.CreateTemplatePicker.DisableEvents();
        TemplateItem templateItem = Client.ContentDatabase.Templates.CreateTemplate(this.TemplateName.Value, selectionItem);
        this.CreateTemplatePicker.EnableEvents();

I have tried the following:

        Client.Site.Notifications.Disabled = true;
        var item = container.Add(ItemUtil.ProposeValidItemName(this.Title.Value), Settings.ProductImageTemplateID);
        Client.Site.Notifications.Disabled = false;

AND OLSO

        Item item;
        using (new EventDisabler())
        {
            item = container.Add(ItemUtil.ProposeValidItemName(this.Title.Value), Settings.ProductImageTemplateID);
        }

All with the same result. The wizard modal dialog is reloaded as soon as I get to the page where the item is created. Using fiddler I can see the command to reload the windows is sent to the client. I just cant figure out how do I tell Sitecore UI to ignore the event(s) or alternatively prevent event(s) from being generated in the first place. The first command being sent to the UI below tells the page to load Content Editor, exactly the thing I'm trying to prevent.

{"commands":[
    {"command":"SetLocation","value":"/sitecore/shell/sitecore/content/Applications/Content%20Editor.aspx?fo=%7b186F686E-A8FF-4303-B59F-4D284A5A0196%7d&db=master&id=%7B186F686E-A8FF-4303-B59F-4D284A5A0196%7D&la=en&vs=1"},
    {"command":"SetDialogValue","value":"{186F686E-A8FF-4303-B59F-4D284A5A0196}"},
    {"command":"SetStyle","value":"none","id":"Constraints","name":"display"},
    {"command":"SetStyle","value":"","id":"LastPage","name":"display"},
    {"command":"SetAttribute","value":true,"id":"NextButton","name":"disabled"},
    {"command":"SetOuterHtml","value":"<button id=\"CancelButton\" class=\"scButton\" TabIndex=\"0\" onclick=\"javascript:return scForm.postEvent(this,event)\" onkeydown=\"javascript:scForm.handleKey(this, event, null, &#39;32&#39;)\">Finish</button>","id":"CancelButton"},
    {"command":"Focus","value":"CancelButton","scrollintoview":"0"},{"command":"Eval","value":"scUpdateWizardControls();"},
    {"command":"SetAttribute","value":true,"id":"BackButton","name":"disabled"},{"command":"Eval","value":"scAlignWizardButtons()"}
    ]}

Just a little info about my Sitecore environment:

Sitecore started
Sitecore.NET 7.0. (rev. 130810)

C:\Inetpub\wwwroot\sc71\Website\bin\Sitecore.Client.dll (Sitecore CMS, Sitecore Client Application, 7.0 rev. 130810)
C:\Inetpub\wwwroot\sc71\Website\bin\Sitecore.Kernel.dll (Sitecore CMS, Sitecore CMS Kernel Library, 7.0 rev. 130810)
C:\Inetpub\wwwroot\sc71\Website\bin\Sitecore.Nexus.dll (Sitecore.Nexus)

Operating system Microsoft Windows NT 6.2.9200.0

Microsoft.NET version 4.0.30319.18051

Process id: 8040
Windows identity used by the process: NT AUTHORITY\NETWORK SERVICE. Impersonation: False
Managed pipeline mode: Integrated
Was it helpful?

Solution

In the end the problem only affected bucketable items. No need to disable event or anything, that was a red herring. However, in my case I am working with buckets and bucketable items, so I needed to get it fixed.

The offending code ended being Sitecore.Buckets.Commands.AddFromTemplateCommand(). Thanks to Sitecore support engineers for getting to the bottom of this. A proposed workaround, that worked for me is as follow. This have been reported to Sitecore development team and I guess will be resolved at some stage in a future release of Sitecore. The current (at the time of writing) version Sitecore.NET 7.0. (rev. 130810) is affected.

You will need to substitute existing implementation with your own (see code below). To replace existing implementation overwrite the following configuration /App_Config/Includes/Sitecore.Buckets.config file at /sitecore/databases/database[@id="master"]. I ended up creating a configuration patch file that looked like this.

Configuration:

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <databases>
      <database id="master" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">

        <Engines.DataEngine.Commands.AddFromTemplatePrototype>

          <obj patch:instead="obj[@type='Sitecore.Buckets.Commands.AddFromTemplateCommand, Sitecore.Buckets']"
               type="Sitecore.Support.Buckets.Commands.AddFromTemplateCommand, MyAssembly"/>

        </Engines.DataEngine.Commands.AddFromTemplatePrototype>
      </database>
    </databases>
  </sitecore>
</configuration>

Code:

using Sitecore.Data.Items;
using Sitecore.Text;
using Sitecore.Web.UI.Sheer;
using System;
using System.Web;

namespace Sitecore.Support.Buckets.Commands
{
    public class AddFromTemplateCommand : Sitecore.Buckets.Commands.AddFromTemplateCommand
    {
        protected override Sitecore.Data.Engines.DataCommands.AddFromTemplateCommand CreateInstance()
        {
            return new AddFromTemplateCommand();
        }

        protected override void SetLocation(Data.Items.Item item)
        {
            if ((HttpContext.Current != null) && (Context.ClientPage != null))
            {
                // This condition is set to go around an issue when a bucket item is created from within a custom wizard app.
                // Replace the specified path with your own one.
                if (Sitecore.Context.RawUrl != null && !Sitecore.Context.RawUrl.Contains("/sitecore/shell/Applications/Issues/Create Product Bucket.aspx"))
                {
                    UrlString str = new UrlString(Sitecore.Buckets.Util.Constants.ContentEditorRawUrlAddress);
                    str.Add(Sitecore.Buckets.Util.Constants.OpenItemEditorQueryStringKeyName, item.ID.ToString());
                    item.Uri.AddToUrlString(str);
                    UIUtil.AddContentDatabaseParameter(str);
                    SheerResponse.SetLocation(str.ToString());
                }
            }
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top