11

I would like to have an extension (GUI) on Component Save and Close checking if all fields have proper values.

I have not written any extensions still and will start with by simply throwing an alert on save and close.

Please suggest the steps need to be followed for any sample extension creation for 2009.

Any sample will help me here.

Thanks and Regards, Anupam

10

You can do that (alert) without a GUI extension, simply by using Event System (OnComponentSavePre event). The GUI extension framework is very different in 2011 and 2013, I would not recommend doing a real extension for 2009, as you would have to rebuild it once you upgrade.

Creating a Tridion 2009 Event System is not as simple as 2011 or 2013, but definitely simpler than GUI extensions.

You need to:

  1. Create a new "Class Assembly" project in Visual Studio
  2. Make sure you're compiling for .NET 2.0 or 3.5 (not 4)
  3. Add references to Tridion.ContentManager.Interop.cm_tom.dll, Tridion.ContentManager.Interop.cm_defines.dll and Tridion.ContentManager.Interop.msxml4.dll (you will find these files under Tridion\bin\PIA)
  4. Write code along the following lines:
using System;
using System.Xml;
using Tridion.ContentManager.Interop.TDSDefines;
using Tridion.ContentManager.Interop.TDS;
using Tridion.ContentManager.Interop.msxml4;

namespace yourNamespace.goes.here
{
    [System.Runtime.InteropServices.ComVisible(true)]
    [System.Runtime.InteropServices.ProgId("TDSEvents.Events")]
    public sealed class Events : ITCMEvents
  1. At this point Visual Studio will propose that you press TAB and it will create all the methods for you.

You will then want to find the Identity property and change it from:

public string Identity
{
    set { throw new Exception("The method or operation is not implemented."); }
}

to

private string _identity;
public string Identity
{
    get {return _identity;}
    set {identity = value;}
}

Then you'll search for OnComponentSavePre, and start implementing the logic to read through the fields of your components - whenever you find conditions that are not OK, use throw new Exception("Content of field X is wrong");. Users will see the text of the exception on their screens and will not be able to save.

You then need to tell Tridion that you have custom code for a specific event - you do that by opening the Tridion Content Manager snap-in, find the Event Configuration node, then finding Component -> Event triggered before saving a component. Change that value from 0 to 1.

Once you're done with that, you'll need deploy this assembly on your servers using regasm. Google is your friend there.

Last, very important point.

Events like these get triggered on every save of every component. Your code should quickly decide if it needs to execute based on information like schema.Title, and exit as soon as it realizes it has nothing to do. Do make sure you know what you're trying to achieve before you start.

If you have access to the old forum, check this thread for more details.

PS: the same process for Tridion 2011 and higher is somewhat shown here. It's a lot simpler...

| improve this answer | |
  • Thanks for your reply. Actually, i want to achieve this using Tridion GUI extensions as current Events are causing some memory lecakge issues. So could you please suggest how this can be achieved using extensions? – Anupam Baksi Jun 26 '13 at 9:57
  • Not for Tridion 2009, maybe others can. – Nuno Linhares Jun 26 '13 at 10:00
  • 2
    Mr. Linhares actually created an extension for exactly this functionality and I posted it on my blog, Validating Tridion Content on Save using Anguilla, curlette.com/?p=913. For memory leakage issues - make sure you are releasing all of your COM objects with Marshal.ReleaseComObject. – robrtc Jun 26 '13 at 12:03
  • Many thanks for the reply Robert.I am checking this now as well. Could you please let me know how i can simply configure any extensions in 2009 version? – Anupam Baksi Jun 27 '13 at 7:48
4

Yoav Niran describes the basic SDL Tridion 2009 GUI extension approach in this post. You would configure the extension in Extension.xml and create your code in Script.js.

His example even includes code for schema field validation, in (near) real-time.

| improve this answer | |
  • Thanks Alvin, i will check this and will inform you. Also, i have tried to deploy one sample extension, but did not found the Webui or Editors directory like in 2011. Can you please tell me steps to deploy/configure any extensions in 2009? Thanks in advance. – Anupam Baksi Jun 27 '13 at 7:42
  • As I mentioned, the UI changed completely between 2009 and 2011 - your extensions for 2009 will NOT work with 2011 and vice versa. – Nuno Linhares Jun 27 '13 at 8:00
  • Thanks again Nuno. Could you please tell me the simplest way to show an alert "HI" on any component save and close using extensions in 2009? I have modified the Extension.XML and have added section where i am pointing to a simple javascript but, it is not showing any message. Please suggest. – Anupam Baksi Jun 27 '13 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.