Tuesday, April 16, 2013

Extending Tridion 2013 Workflow scripts

One of the most important things in technology is curiosity and this will lead you to find new ways to do things, the other day I was checking all the Tridion 2013 configuration files and I realized that the new version of Tridion.ContentManager.config file has a new section that allow me to register different types of Workflow Scripts.

<workflowScriptTypes>
  <add
    name="CSharp"
    titleResource="msgCSharpWorkflowScriptType"
    scriptContentHandlerType="Tridion.ContentManager.Workflow.CSharpScriptContentHandler"
    executorType="Tridion.ContentManager.Workflow.CSharpScriptExecutor"
    assemblyName="Tridion.ContentManager.Workflow, Version=7.0.0.2303,  Culture=neutral, PublicKeyToken=ddfc895746e5ee6b" />
 
  <add
    name="ExternalActivity"
    titleResource="msgExternalActivityScriptType"
    scriptContentHandlerType="Tridion.ContentManager.Workflow.ExternalActivityScriptContentHandler"
    executorType="Tridion.ContentManager.Workflow.ExternalActivityExecutor"
    assemblyName="Tridion.ContentManager.Workflow, Version=7.0.0.2303, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b" />
</workflowScriptTypes>

This feature is not documented but with some .Net knowledge we will make it to work

What I need to create my own Workflow Script Type?

It is mandatory to develop 2 classes, one to execute your new script type and one to validate it.

Script Type Executor

In order to develop a new Script Type Executor we will need implement the IScriptExecutor interface and implement the ExecuteScript method as in the following sample.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.ServiceModel;
using System.Text;
using System.Text.RegularExpressions;
using Tridion.ContentManager;
using Tridion.ContentManager.CoreService.Client;
using Tridion.ContentManager.Workflow;
using Tridion.Extension.Framework.Workflow.Handlers;
using Tridion.Localization;
using Tridion.Logging;

namespace Tridion.Extension.Framework.Workflow {
    public class YAWFActivityExecutor : IScriptExecutor {

        public string ExecuteScript(string script, string currentActivityInstanceId, string processInstanceXml) {
           
        }
    }
}

The ExecuteScript receives the following parameters.
  • Script: the script specified in the Activity Script box.
  • currentActivityInstanceId: executing activity id, it is the starting point to start creating tridion objects.
  • processInstanceXml: process instance xml, it will allow you to manage Process Variables.

Script Content Handler

This class will validate your script and make sure it is a valid script. The syntax depends on you since the script you are defining is your own design.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tridion.ContentManager.Workflow;

namespace Tridion.Extension.Framework.Workflow {
    public class YAWFActivityScriptContentHandler : ScriptContentHandler {
        public override void Validate() {
           
        }
    }
}

Registering your Script Type

The assembly needs to have a strong name and be registered in the GAC. Once your assembly is registered in the GAC the next step is to add your script to the list of WorkflowScriptTypes.

<workflowScriptTypes>
    <add
        name="CSharp"
        titleResource="msgCSharpWorkflowScriptType"
        scriptContentHandlerType="Tridion.ContentManager.Workflow.CSharpScriptContentHandler"
        executorType="Tridion.ContentManager.Workflow.CSharpScriptExecutor"
        assemblyName="Tridion.ContentManager.Workflow, Version=7.0.0.2303,  Culture=neutral, PublicKeyToken=ddfc895746e5ee6b" />
    <add
        name="ExternalActivity"
        titleResource="msgExternalActivityScriptType"
        scriptContentHandlerType="Tridion.ContentManager.Workflow.ExternalActivityScriptContentHandler"
        executorType="Tridion.ContentManager.Workflow.ExternalActivityExecutor"
        assemblyName="Tridion.ContentManager.Workflow, Version=7.0.0.2303, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b" />
    <add
        name="YAWF ExternalActivity"
        scriptContentHandlerType="Tridion.Extension.Framework.Workflow.YAWFActivityScriptContentHandler"
        executorType="Tridion.Extension.Framework.Workflow.YAWFActivityExecutor"
        assemblyName="WorkflowFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=a7e94891d1e8b7e1" />
</workflowScriptTypes>

Using your Custom Script

You should be able to see it in the Workflow Designer in Visio.



And add your own script

1 comment:

  1. Thanks for this post! Excellent starter point for me to create the Java version of YAWF. I think I'll call it JAWF... or JAWS? :)

    ReplyDelete