-1

I am trying to finish the activity after publishing the component from workflow.

Publishing is done, and am getting error ("Object instance not set to an instance object") after setting the finish activity message.

ActivityFinishData activityfinish = new ActivityFinishData();
activityfinish.Message = "Published to WIP Publication Target";
logdetails("Finish Message able to Set using Code,the below is the finish message");
logdetails(activityfinish.Message);
ProcessInstanceData processInstance = new ProcessInstanceData();
ActivityInstanceData activityInstance = (ActivityInstanceData)processInstance.Activities[0];
logdetails(activityInstance.Title.ToString());
logdetails(activityInstance.Id.ToString());
csClient.FinishActivity(activityInstance.Id, activityfinish, readoption);
logdetails("Workflow Finished");
Jeremy Grand-Scrutton
  • 2,802
  • 14
  • 20
Jey
  • 2,137
  • 4
  • 22
  • 40
  • 1
    By now you've asked about a dozen questions about this same area in the past two weeks. At this stage you should know what "Object instance not set to an instance object" means and how to go about debugging it. That doesn't mean you can't get stuck along the way, but you should be able to provide us with better information to help you. – Frank van Puffelen Jul 11 '12 at 12:34
  • 1
    You really insist on using a new process everytime, don't you? - ProcessInstanceData processInstance = new ProcessInstanceData(); – Nuno Linhares Jul 11 '12 at 13:04
  • That's a *very* good point that Nuno raises - you're getting new instances of the appropriate object when you should actually be getting existing objects (or at least objects that represent things that exist). If you get a new ProcessInstanceData object then it will have no activity instances so you won't have anything to finish... – Jeremy Grand-Scrutton Jul 11 '12 at 13:16
  • As Nuno already wrote you will get this exception due to next lines: ProcessInstanceData processInstance = new ProcessInstanceData(); ActivityInstanceData activityInstance = (ActivityInstanceData)processInstance.Activities[0]; Because you are creating a NEW process instance which doesn't have any activities yet. Most probably you need to read existing process instance by next call csClient.Read("SOMEID", readOption) – Igor Paniushkin Jul 12 '12 at 09:45

1 Answers1

2

The following approach worked for me:

SessionAwareCoreServiceClient client = Client.GetCoreService();
ReadOptions options = new ReadOptions();

WorkItemData workItem = (WorkItemData)client.Read(currentWorkItemId, options);
ProcessInstanceData processInstance =
    (ProcessInstanceData)client.Read(workItem.Process.IdRef, options);
ActivityInstanceData activityInstance =
   (ActivityInstanceData)client.Read(processInstance.Activities[0].Id, options);

ActivityFinishData finishData = new ActivityFinishData();
finishData.Message = "Finished automatically";

client.FinishActivity(activityInstance.Id, finishData, options);
client.Close();

You can see that I start with the Id of the current work item and get existing object from there. The only objects I create as "new" are ones that don't already exist.

Jeremy Grand-Scrutton
  • 2,802
  • 14
  • 20
  • @Jermery: I have initiated the readoption in my function as var readoption = new ReadOptions(); and used in finish activity call. ( i have pasted the part of the code which not working about to finish the workflow activity. – Jey Jul 11 '12 at 12:43
  • Never mind. I see that Nuno has identified the likely cause of the problem. – Jeremy Grand-Scrutton Jul 11 '12 at 13:16