3

I have a manual activity first and then 2nd activity is an automatic decision activity. I have written a C# class library and uploaded in TCM as TBB. In my automatic decision activity, I have provided the code as below in the Edit script.

AssemblyTbbId = "/webdav/xyx/myworkflow.tbbasm"
Type = "myworkflow.myclass"

And below is the code in my TBB. I am getting the error below.

Tridion.ContentManager.Workflow.WorkflowEngineException: Activity instance '2. Super User?' (tcm:2-32-131104) must be in 'Finished' state after script

log is also not created in the TCM server. Do i need to register the dll in TCM? I just uploaded in TCM only.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tridion.ContentManager;
using Tridion.ContentManager.CoreService.Client;
using Tridion.ContentManager.CoreService.Workflow;

namespace myworkflow
{
public class myclass : ExternalActivity
{        
    protected override void Execute()
    {
        logdetails("Inside checkSuperUser method");
        SessionAwareCoreServiceClient cSclient = new SessionAwareCoreServiceClient();
        ActivityInstanceData currentActivityInstance = cSclient.Read(ActivityInstance.Id, new ReadOptions()) as ActivityInstanceData;
        Boolean isSuperUser = GetLastPermformerIdofCreateAndEdit(currentActivityInstance);
        ActivityFinishData finishActivity = new ActivityFinishData();

        if (isSuperUser)
        {

            finishActivity.Message = currentActivityInstance.FinishMessage;
            finishActivity.NextActivityTitle = "Approver";                
        }
        else
        {
            finishActivity.Message = currentActivityInstance.FinishMessage;
            finishActivity.NextActivityTitle = "Editor";
        }
        cSclient.FinishActivity(currentActivityInstance.Id, finishActivity, new ReadOptions());
    }        
    }
    }

1 Answer 1

5

For an automatic decision activity I think you need to use a DecisionActivityFinishData, rather than an ActivityFinishData, and you need to set it's NextActivity property.

Also - I don't think you need to instantiate a new Core Service client or an object for the current activity - You are given these already as part of the inheritance of the ExternalActivity class.

Suggest you try an Execute method something like the following:

protected override void Execute()
{
    logdetails("Inside checkSuperUser method");
    Boolean isSuperUser = GetLastPermformerIdofCreateAndEdit(ActivityInstance);
    ActivityFinishData finishActivity = new DecisionActivityFinishData();

    if (isSuperUser)
    {
        finishActivity.Message = ActivityInstance.FinishMessage;
        finishActivity.NextActivity = GetNextActivityByTitle("Approver");
    }
    else
    {
        finishActivity.Message = ActivityInstance.FinishMessage;
        finishActivity.NextActivity = GetNextActivityByTitle("Editor");
    }

    CoreServiceClient.FinishActivity(ActivityInstance.Id,
        finishActivity,
        new ReadOptions());
}

My GetNextActivityByTitle method is as follows:

private LinkToActivityDefinitionData GetNextActivityByTitle(string nextActivityTitle)
{
    var currentActivity = (ActivityDefinitionData)CoreServiceClient.Read(ActivityInstance.ActivityDefinition.IdRef, new ReadOptions());
    var currentTridionActivity = (TridionActivityDefinitionData)currentActivity;

    foreach (var linkToTridionActivityDefinitionData in currentTridionActivity.NextActivityDefinitions)
    {
        if (String.Compare(linkToTridionActivityDefinitionData.Title, nextActivityTitle, StringComparison.OrdinalIgnoreCase) == 0)
        {
            return new LinkToActivityDefinitionData { IdRef = linkToTridionActivityDefinitionData.IdRef };
        }
    }
    return null;
}
7
  • Thanks David, i have used the code as you given with DecisionActivityFinishData finishActivity = new DecisionActivityFinishData(); However, still i am getting the same error "Tridion.ContentManager.Workflow.WorkflowEngineException: Activity instance '2. Super User?' (tcm:2-40-131104) must be in 'Finished' state after script execution by Workflow Agent, but actual state is 'Started'. at Tridion.ContentManager.Workflow.WorkflowAgentEngine.ProcessActivity(TcmUri activityInstanceId)" And Log file is also not created in the given location. state is Failed
    – Jey
    Commented Mar 10, 2014 at 12:35
  • In that case I suspect there is something wrong in your logdetails() method. The way that the ExternalActivity class you're inheriting is written, the call to Execute() is wrapped with a try block. Try commenting out the log call and/or sharing that code. Commented Mar 10, 2014 at 14:05
  • I commented out the log line. still the same error. BTW, below is my logdetails code and (if i am right )which i am exptecting to create the log file in the TCM server. public void logdetails(string strlogdetails) { using (StreamWriter writer = new StreamWriter(@"C:/tridion/workflow/log.txt", true)) { writer.WriteLine(DateTime.Now.ToString() + "=====>|" + strlogdetails); writer.Close(); } }
    – Jey
    Commented Mar 10, 2014 at 14:22
  • 1
    OK. Sounds like something is still throwing an exception somewhere in the Execute method because the call to CoreServiceClient.FinishActivity is not being reached. Perhaps in the GetLastPermformerIdofCreateAndEdit() method? Best thing is to step through your External activity on a development server by connecting to the TcmWorkflowAgent.exe process. Commented Mar 10, 2014 at 14:32
  • I will check David, any thought that why log file is not created, it is the first line in the execute method.
    – Jey
    Commented Mar 10, 2014 at 16:23

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.