2

I'm using Tridion 2013 SP1. I'm getting below error while finishing an automatic activity from a decision activity.

Here is my code:

var session = new Session();
WorkItem  m_WorkItem = session.GetObject(workitemid) as WorkItem;
ActivityInstance currentactivity = m_WorkItem.Activity as ActivityInstance;
IEnumerable<ActivityDefinition> ieActivities = currentactivity.ActivityDefinition.ProcessDefinition.ActivityDefinitions;
ActivityDefinition activityInstance = ieActivities.ToList().Where(c => c.Title == "Publish EN to Testing and Staging").First();
DecisionActivityFinish finish = new DecisionActivityFinish(activityInstance, session.User, "Publish EN to Testing and Staging", session);
currentactivity.Finish(finish);

Error on the event viewer is like this,

Unable to get activity instance from work item. caused by: WorkItem.ActivityInstance

and description:

<?xml version="1.0"?>
<tcm:Error xmlns:tcm="http://www.tridion.com/ContentManager/5.0" ErrorCode="D" Category="18" Source="Kernel" Severity="1">
    <tcm:Line Cause="false" MessageID="16138"><![CDATA[Unable to get ActivityInstance of Workflow work item (tcm:3-125-131200).]]><tcm:Token>RESID_4485</tcm:Token>
        <tcm:Token>ActivityInstance</tcm:Token>
        <tcm:Token>RESID_15212</tcm:Token>
        <tcm:Token>tcm:3-125-131200</tcm:Token>
    </tcm:Line>
    <tcm:Line ErrorCode="D" Cause="true"><![CDATA[Type mismatch]]></tcm:Line>
    <tcm:Details>
        <tcm:CallStack>
            <tcm:Location>WorkItem.ActivityInstance</tcm:Location>
            <tcm:Location>WorkItem.ActivityInstance</tcm:Location>
        </tcm:CallStack>
    </tcm:Details>
</tcm:Error>

Workflow diagram

2 Answers 2

3

I think, it's going wrong while casting

ActivityInstance currentactivity = m_WorkItem.Activity as ActivityInstance;

Try changing to

ActivityInstance currentactivity = (ActivityInstance)m_WorkItem.Activity;

Update:

For Automatic Activities, you should use Core Services.

Example:

WorkItemData mWorkItemData = (WorkItemData)mClient.Read(workItemId, mReadOptions);
ActivityInstanceData mCurrentActivity = (ActivityInstanceData)mClient.Read(mWorkItemData.Activity.IdRef, mReadOptions);
TridionActivityDefinitionData mTridionActivityDefinition = (TridionActivityDefinitionData)mClient.Read(mCurrentActivity.ActivityDefinition.IdRef, mReadOptions);
ProcessDefinitionData mProcessDefinition = (ProcessDefinitionData)mClient.Read(mTridionActivityDefinition.ProcessDefinition.IdRef, mReadOptions);
IList<ActivityDefinitionData> mActivityDefinitionList = new List<ActivityDefinitionData>(mProcessDefinition.ActivityDefinitions);

ActivityDefinitionData mNextActivity = (ActivityDefinitionData)mActivityDefinitionList.Where(c => c.Title == "Publish EN to Testing and Staging").FirstOrDefault();

if (mNextActivity != null)
{
    DecisionActivityFinishData mDecisionActivityFinishData = new DecisionActivityFinishData
    {
        NextActivity = new LinkToActivityDefinitionData { IdRef = mNextActivity.Id }
    };
    mClient.FinishActivity(mCurrentActivity.Id, mDecisionActivityFinishData, mReadOptions);
}

Note: I have not tested above code, just wrote for you.

3
  • Thanks Siva your code is perfectly running and my problem also solved.thanks again Commented Jan 27, 2014 at 11:16
  • Siva how to check in which context the item is originally created after localize in core service?? Commented Jan 27, 2014 at 11:42
  • That sounds like a different question - please open a new question instead of burying it in the comments...
    – Nuno Linhares
    Commented Jan 27, 2014 at 22:27
3

Here a sample using an External Activity source code.

ProcessDefinitionData ProcessDefinition = (ProcessDefinitionData)CoreServiceClient.Read(ProcessInstance.ProcessDefinition.IdRef, ReadOptions);

ActivityDefinitionData NextActivity = (ActivityDefinitionData)CoreServiceClient.Read(ProcessDefinition.ActivityDefinitions.Where(w => w.Title.IndexOf("Publish EN to Testing and Staging") != -1).ElementAt(0).Id, ReadOptions);

CoreServiceClient.FinishActivity(ActivityInstance.Id, new DecisionActivityFinishData() {
        Message = "Finish Message",
        NextAssignee = GetNextAssignee(), 
        NextActivity = new LinkToActivityDefinitionData() { IdRef = NextActivity.Id }
    }, 
new ReadOptions());

Notice that I don't need to write code to get the current Activity Instance since it is already available in the ActivityInstance property as well as for the CoreServiceClient object.

As answered above, you shouldn't use the TOM .NET API to manipulate Workflow Objects unless you are doing it in an Event System. If your intention is to run that code in an Automatic Activity (C# or External) you must use Core Services.

1
  • +1 And definitely should not be creating TOM.NET sessions in your code, that's asking for trouble.
    – Nuno Linhares
    Commented Jan 26, 2014 at 15:48

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.