I fixed the following error in a Bundle Workflow process. I couldn't find this specific scenario online (except for a somewhat related SO question); see answer below.

System.ArgumentException: An item with the same key has already been added. at Tridion.ContentManager.Workflow.WorkflowAgentEngine.ProcessActivity(TcmUri activityInstanceId)

This example is adapted from Build Block's 2013 preview example with a minor update for to CurrentActivityInstance, which Eric Huiza describes as one of the variables we get "for free" with Automatic Activities (similar to C# fragments, but for Core Service with Workflow).

<%@ Import Namespace="System.ServiceModel"%>
<%@ Import Namespace="System.Runtime.Serialization"%>

// Adapted from Post-Bootcamp example from Building Blocks

PublishInstructionData publishInstruction = new PublishInstructionData();
publishInstruction.ResolveInstruction = new ResolveInstructionData();
publishInstruction.RenderInstruction = new RenderInstructionData();
publishInstruction.ResolveInstruction.IncludeWorkflow = true;

ActivityInstanceData activityInstance = CurrentActivityInstance;

IList<String> itemsToPublishList = new List<String>();
//Staging publication target URI
String[] targets = new[] { "tcm:0-1-65537" };

foreach (WorkItemData wid in activityInstance.WorkItems)
  int value = Convert.ToInt32(Enum.Parse(typeof(ItemType), "VirtualFolder"));
  if (wid.Subject.IdRef.EndsWith(value.ToString()))
PublishTransactionData[] publishTransactions = SessionAwareCoreServiceClient.Publish(itemsToPublishList.ToArray<String>(), publishInstruction, targets, PublishPriority.Normal, null);
ProcessInstance.Variables.Add("PublishTransaction", publishTransactions[0].Id);

SessionAwareCoreServiceClient.FinishActivity(activityInstance.Id, new   ActivityFinishData { Message = "Publish to Staging Queued: Finished Activity" }, null);

This works as a script for a single Automatic Activity, but throws an error when attempting to use the same code to publish to Staging and then Live in another activity (even when changing the Publication Target ID).


This was a copy-and-paste error in:

ProcessInstance.Variables.Add("PublishTransaction", publishTransactions[0].Id);

Per the Core Service API, ProcessInstanceData has a Variables member, which is a VariablesDictionary. Dictionary's can't have duplicate keys.

The fix is changing the string "PublishTransaction" to be different per automatic activity. We could also use external activities and create a "publish" method as seen in Eric Huiza's (pre-release) 2013 Workflow examples (see update below).

Update: see Eric's more recent post on 2013 Tridion Workflows (GA) for examples of workflow for external activities using an object-oriented approach.

| improve this answer | |

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.