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");
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.