0

The below back to author code is not working in core service based workflow.

and not giving any error. any suggestions?

public void BackToAuthor(string workitemid)
{
  var client = new CoreServiceSession();
  var csClient = client.GetClient();
  var readoption = new ReadOptions();

  var workitem = (WorkItemData)csClient.Read(workitemid, readoption);
  var processInstance = (ProcessInstanceData)csClient.Read(
                                             workitem.Process.IdRef, readoption);
  var ieActivities = processInstance.Activities;

  if (ieActivities != null)
  {
    var targetactivity = (ActivityInstanceData)csClient.Read(
                                  processInstance.Activities[0].Id, readoption);
    var finishData = new ActivityFinishData();
    finishData.Message = "Finished automatically";
    finishData.NextAssignee = new LinkToTrusteeData { 
        IdRef = processInstance.Activities[0].Performers[0].IdRef, 
        Title = processInstance.Activities[0].Performers[0].Title };
      csClient.FinishActivity(targetactivity.Id, finishData, readoption);
      logdetails("Finished the activity");
      csClient.Close();
  }
}
Jey
  • 2,137
  • 4
  • 22
  • 40
  • It's probably not the cause of your problem, but I suggest **not** catching the exception and instead letting it escape. Whoever called your code probably will do a better job at logging it then your custom `logdetails` does. – Frank van Puffelen Jul 17 '12 at 14:23
  • Frank, you mean, the code is correct? if so, then why the item is not moved back to the author? any clue? – Jey Jul 17 '12 at 14:38
  • 1
    One of the mistakes in your code is catching an exception that you don't handle. That has nothing to do with the problem you're reporting (otherwise I would have provided an answer and not a comment), but will hurt your users once you put it into production. – Frank van Puffelen Jul 17 '12 at 15:16
  • Ok, I have changed the code to assing to performer instead of owner, but am getting error in event log "The workflow activity is finished" and still the item is not moved to the last performer, it sits in the global worklist itself (In the automatic activity "back to author") – Jey Jul 17 '12 at 15:28

3 Answers3

3

I believe you have to send the activity back to the performer not to the owner (which is "everyone" for the very first activity). You might have to change the following lines of code...

finishData.NextAssignee = new LinkToTrusteeData { 
        IdRef = processInstance.Activities[0].Performer.IdRef, 
        Title = processInstance.Activities[0].Performer.Title };
Ram G
  • 4,829
  • 1
  • 16
  • 26
  • I have changed the code to assing to performer instead of owner, but am getting error in event log "The workflow activity is finished" and still the item is not moved to the last performer, it sits in the global worklist itself (In the automatic activity "back to author") – Jey Jul 17 '12 at 15:28
  • 1
    What is error message you're getting ? Could you please post the stack trace or full event log.. – Ram G Jul 17 '12 at 15:36
  • 1
    An error occurred while executing the Workflow script. The Script Engine returned the following information: SOURCE: Line = 6 Column = 4 Number = -2146233087 Source = mscorlib Description = The Workflow Activity is finished. HelpContext = 0 caused by: mscorlib and description: The Workflow Activity is finished. Source: LogScriptError – Jey Jul 17 '12 at 15:47
  • Is the Line 6 VBScript where you're calling the BackToAuthor function? – Ram G Jul 17 '12 at 16:04
  • Yes Ram, i am calling BackToAuthor function from the vbscript – Jey Jul 17 '12 at 16:05
  • Code looks good to me, not sure why it is failing. You can run the debugger to step thru and see where it is failing. targetactivity.Id --> Is this returning a TcmUri or string ? It should be string. You can also check here on how to debug, http://stackoverflow.com/questions/11366385/how-to-debug-tridion-templates-and-workflows – Ram G Jul 17 '12 at 16:23
1

Can you check the ActivityInstanceData.ActivityState (processInstance.Activities[0]) property? When it's finished already you will get the exception you mentioned. In that case you need to restart the activity: ICoreService2011.RestartActivity(activityInstanceId, readBackOptions)

So, how does your process definition look like? Is BackToAuthor called from an Automatic Activity, after the first Activity in the Process Definition?

Arjen Stobbe
  • 1,684
  • 9
  • 15
  • first activity is "create or edit", second is "Review", if reviewer rejects, am calling the Backtoauthor automated activity, otherwise calling publish activity this is also automated activity. – Jey Jul 17 '12 at 18:35
1

I'd suggest first that you get the code running under a debugger, and verify that the Ids are what you expect. For example, is the process instance correct, and are the various activities and performers what you expect?

Dominic Cronin
  • 6,062
  • 2
  • 23
  • 56