6

I have created some sample External Activities which successful execute when called from the workflow activities in my Visio diagram. My code in my External Activity looks a bit like this:

AssemblyTbbId = "tcm:2010-21343-2048"
Type = "Net.SDLTridion.Workflow.CheckForDispatching"

This calls the Execute() method of my CheckForDispatching class. At the moment I really need to implement a new class for every activity in my workflow process definition. I would really like to parameterize my calls to my classes, so I could have more reusable code. Essentially I would like to be able to achieve something like the following for a decision activity:

Class: CheckIfUserIsAdmin
Execute Method: Execute(String activityIfTrue, String activityIfFalse)….

Is there a way to add some parameters to my Execute() method from within the same activity. The only way I can think to do this is make an additional automated activity which executes before my external activity which looks a bit like this:

ProcessInstance.Variables.Add("activityIfTrue", “Activity Name 1”);
ProcessInstance.Variables.Add("activityIfFalse", “Activity Name 2”);

These could then be read from the external activity class in the subsequent step. This feels like a very long winded approach, and I am hoping someone can suggest a better way.

1 Answer 1

6

I had the same issue before and I found 2 possible solutions.

1) Implement your own Script Executor, you can find details about it here.

Extending Workflow Scripts

2) Pass parameters to the standard script executor in the following way.

AssemblyTbbId = "tcm:2-7070-2048"
Type = "Tridion.ContentManager.Spark.Workflow.Publish.PublishToDevActivity"
ResultAware = True

As you can see there I am passing a parameter called ResultAware but I am not putting the value in Quotes (that is a hack so that the script validator will accept my script)

Then you can access to that value in your external activity like this.

private static readonly Regex NameValuePairRegex = new Regex(@"\s*(?<Name>[^""]+)\s*=\s*(?<Value>[^""]+)\s*", RegexOptions.Compiled);
public TridionActivityDefinitionData ActivityDefinition { get; set; }

private bool GetResultAware() {
    IEnumerable<Match> matches = NameValuePairRegex.Matches(ActivityDefinition.Script).Cast<Match>();
    if (matches.Count() > 0) {
        Match resultAwareMatch = matches.FirstOrDefault(m => m.Groups["Name"].Value.Equals(PublishConstants.ResultAwareParam));
        if (resultAwareMatch != null) {
            bool result;
            bool.TryParse(resultAwareMatch.Groups["Value"].Value, out result);
            return result;
        }
    }
    return false;
}
6
  • 2) is really a hack (I didn't expect, that it is possible) + not documented. As I understand, during implementation of this approach assumed, that user will share his additional parameters through Process Instance variables (btw - it on of the reason, why it is available in ExternalActivity class). So idea was, that before finishing one activity you save some variable(to PI.Variables), and you can use it during execution another activity.
    – Syav4eg
    Commented Oct 24, 2013 at 7:52
  • I tend to agree that #2 is a hack, but using the PI.Variables involves making a lot of extra activities, and complicating the WF development process in my opinion. Thanks @Eric for the great info. Commented Oct 24, 2013 at 16:42
  • I think there is a valid ER here, it would be great to be able to add PI.Variables in the Visio box for External Activities so you don't need to do it in the previous activity. Anyone else agree? Commented Oct 24, 2013 at 16:44
  • Honestly, I don't agree.PI.Variables must be used for specific ActivityInstances(so, you have activity instance and want to share some info with another ActivityInstance). But activityinstance is some dynamic stuff...As I've understood you want to deal with ActivityDefinitions in static context (all ActivityInstances created for this ActivityDefinitions will used the same values...so they are static, not dynamic). Why in this case not to use ApplicationData for specific activityDefinition? Probably ApplicationData is approach, when you must add some additional information to Tridion objects.
    – Syav4eg
    Commented Oct 24, 2013 at 21:04
  • OK, probably PI variables is not the way to go, but something officially supported like Eric's "Option #2" would be very convenient, and make creating workflow process definitions from pre-made modular classes very easy. That way a "Non-Developer" can make workflows and just plug in parameters using Visio. Commented Oct 25, 2013 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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