1

I am trying to send the item back to auther in workflow using coresrvice, the below is my code, am getting compile error on casting betweento usrdata to linktotrusteedata.

        WorkItemData workitem = (WorkItemData)csClient.Read(workitemid, readoption);
        ProcessInstanceData processInstance = (ProcessInstanceData)csClient.Read(workitem.Process.IdRef, readoption);
        IEnumerable<ActivityData> ieActivities = processInstance.Activities;

        if (ieActivities != null)
        {
            ActivityInstanceData targetactivity = (ActivityInstanceData)csClient.Read(processInstance.Activities[0].Id, readoption);
            UserData lastperformer = (UserData)csClient.Read(processInstance.Activities[0].Owner.IdRef, readoption);                
            ActivityFinishData finishData = new ActivityFinishData(); 
            finishData.Message = "Finished automatically";
            finishData.NextAssignee = lastperformer;
            csClient.FinishActivity(targetactivity.Id, finishData, readoption); 
            csClient.Close(); 

        }
Jey
  • 2,137
  • 4
  • 22
  • 40

2 Answers2

1

The NextAssignee property is of type Link<TrusteeData> but you are setting it to a UserData object. You probably need to create a new Link and fill in the ID and Title of it.

This should work (untested):

[...]
Link<UserData> lastperformer = processInstance.Activities[0].Owner;                
ActivityFinishData finishData = new ActivityFinishData(); 
finishData.Message = "Finished automatically";
finishData.NextAssignee = new Link<TrusteeData> { Id = lastperformer.Id, Title = lastperformer.Title };
csClient.FinishActivity(targetactivity.Id, finishData, readoption); 
[...]

It's also possible that it can work if you just set NextAssignee to the lastperformer variable, since UserData inherits from TrusteeData - but I'm not certain about that. Give it a try?

Peter Kjaer
  • 4,316
  • 13
  • 23
  • TrusteeData nextassignee = new TrusteeData { Id = processInstance.Activities[0].Owner.IdRef }; finishData.NextAssignee = nextassignee; am trying like this, but still getting convert type error – Jey Jul 17 '12 at 12:33
  • That's not what I wrote, so I'm not surprised that you are still getting the convert error. It needs to be a Link object. – Peter Kjaer Jul 24 '12 at 09:39
0

You have the LinkToUserData object already, so can't you assign processInstance.Activities[0].Owner to finishData.NextAssignee, or use the Owner property (LinkToUserData) to construct a new data object?

Or is there a specific reason you read the UserData?

Arjen Stobbe
  • 1,684
  • 9
  • 15
  • TrusteeData nextassignee = new TrusteeData { Id = processInstance.Activities[0].Owner.IdRef }; finishData.NextAssignee = nextassignee; am trying like this, but still getting convert type error – Jey Jul 17 '12 at 12:33
  • You should not use TrusteeData, UserData or GroupData (that are derived from TrusteeData), but create a LinkToTrusteeData object. Since the Owner property is a LinkToUserData object you can reuse the object, or use it to construct a new data object. – Arjen Stobbe Jul 17 '12 at 12:35
  • LinkToTrusteeData lnktr = new LinkToTrusteeData { IdRef = processInstance.Activities[0].Owner.IdRef, Title = processInstance.Activities[0].Owner.Title }; finishData.NextAssignee = lnktr; Have tried like this also, but the activity is not finished and not moved back to author – Jey Jul 17 '12 at 12:44
  • And when i try to log the lnktr details am getting "Tridion.ContentManager.CoreService.Client.LinkToTrusteeData" but i was expecting the user tcm id or title – Jey Jul 17 '12 at 12:46
  • Can you paste all your code here, or clarify your original answer with what you have? – Arjen Stobbe Jul 17 '12 at 12:59
  • Did you try the Link example as proposed by Peter Kjaer? – Arjen Stobbe Jul 17 '12 at 13:35
  • if (ieActivities != null) { ActivityInstanceData targetactivity = (ActivityInstanceData)csClient.Read(processInstance.Activities[0].Id, readoption); ActivityFinishData finishData = new ActivityFinishData(); finishData.NextAssignee = new LinkToTrusteeData { IdRef = processInstance.Activities[0].Owner.IdRef , Title = processInstance.Activities[0].Owner.Title}; csClient.FinishActivity(targetactivity.Id, finishData, readoption); csClient.Close(); } – Jey Jul 17 '12 at 13:41