Thursday, September 20, 2012

Interacting with Content Editor in Sitecore 6

I recently stumbled across an interesting challenge. The issue was to programmatically select an item from within a custom item editor tab.
In Sitecore 5.x it was quite easy to do. All you need to code was this.
Sitecore.Context.ClientPage.SendMessage(this, string.Format("load:item(id={0})", itemId));
Quite simple, huh?

In Sitecore 6 some revamping has been done to Content Editor and now aforementioned approach does not work. The “SendMessage” method does not broadcast the message called from the custom item editor all the way to parental window of Content Editor. The message is sent to an object of custom editor and gets handled by it.

Here is the way it should be done in Sitecore 6.
string msg = string.Format("window.parent.scForm.postRequest(\"\",\"\",\"\",\"item:load(id={0})\")", itemId);
Sitecore.Web.UI.Sheer.SheerResponse.Eval(msg);
Note: “window.parent” in this message is mandatory. Otherwise it won’t work.

P.S. Saving brain-power energy for whomever stumbles upon.