I'm using Web 8.1 and trying to create a workflow in Visio 2016. My last activity of the workflow is an automatic activity which publishes the item and I'm using an External Activity with the code in the SDL demo page (Demo Code)
using System;
using Tridion.ContentManager.CoreService.Client;
using Tridion.ContentManager.CoreService.Workflow;
namespace ExternalAssemblyProperties
{
public class MyClass : ExternalActivity
{
protected override void Execute()
{
PublishInstructionData publishInstruction = new PublishInstructionData();
publishInstruction.ResolveInstruction = new ResolveInstructionData();
publishInstruction.RenderInstruction = new RenderInstructionData();
String[] itemsToPublish = new [] { "tcm:1-45" };
String[] targets = new [] { "tcm:0-1-65537" };
PublishTransactionData[] publishTransactions = CoreServiceClient.Publish(itemsToPublish, publishInstruction, targets, PublishPriority.Normal, null);
ProcessInstance.Variables.Add("PublishTransaction", publishTransactions[0].Id);
CoreServiceClient.FinishActivity(ActivityInstance.Id, new ActivityFinishData { Message = "Finished" }, null);
}
}
}
I'm getting this error:
Index was outside the bounds of the array.
Component: Tridion.ContentManager.Workflow
Errorcode: 0
User: NT AUTHORITY\SYSTEM
StackTrace Information Details:
at ApprovalWorkflow.MyClass.Execute()
at Tridion.ContentManager.CoreService.Workflow.ExternalActivity.ExecuteInternal(String activityInstanceId, String processInstanceXml, Action action)
at Tridion.ContentManager.CoreService.Workflow.ExternalActivity.Tridion.ContentManager.Workflow.IExternalActivity.Execute(String activityInstanceId, String processInstanceXml)
at Tridion.ContentManager.Workflow.ExternalActivityExecutor.ExecuteScript(String script, String currentActivityInstanceId, String processInstanceXml)
at Tridion.ContentManager.Workflow.WorkflowAgentEngine.<>c__DisplayClass7.<ProcessActivity>b__1()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Tridion.ContentManager.Workflow.WorkflowAgentEngine.ProcessActivity(TcmUri activityInstanceId, Boolean isExpirationExecution)
at Tridion.ContentManager.Workflow.Agent.QueueMessageHandler.HandleMessage()
Any idea what might be happening?
It's my understanding that item to publish can be the tcm of a component and target the tcmid of a target type, that's what I'm using.
Thanks in advance. Guillermo.
Publish
method returns more than zero results (it all depends on system configuration). So, you should first test the number of results before trying to get the first.