It's all about the answers!

Ask a question

Participant workitem can't contact server


Paul B (21313) | asked Sep 10 '15, 1:33 a.m.
Hi all,

I've created a participant to modify a work item. After the save button is pressed, it comes back with an error and says that the server could not be contacted. Below is the code I'm using to try and change the attributes. Any help would be great.

// First check that the operation was a 'save' and get he operation data.
Object data= operation.getOperationData();
if (!(data instanceof ISaveParameter))
return;

// Check that this was a save operation on a work item
ISaveParameter saveParameter= (ISaveParameter) data;
if (!(saveParameter.getNewState() instanceof IWorkItem))
return;
IAuditable auditable = saveParameter.getNewState();
workItemServer = getService(IWorkItemServer.class);
// If everything is correct, the auditable is an WorkItem
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable.getWorkingCopy();
IWorkItem wc2 = workItemServer.findWorkItemById(workItem.getId(), IWorkItem.FULL_PROFILE, monitor);
IWorkItem wc = (IWorkItem) wc2.getWorkingCopy();
wc.setHTMLDescription(XMLString.createFromPlainText("This is a test to see if it works"));
List<String> list = new LinkedList<String>();
list.add("paul");
list.add("thomas");
wc.setTags2(list);
workItemServer.saveWorkItem2(wc, null, null);
}


Thanks
Paul

Accepted answer


permanent link
Ralph Schoon (63.3k33646) | answered Sep 10 '15, 3:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
The problem most likely is, that you kill your server, because your save triggers another save and so forth. You run into a recursive loop that never ends. See https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ for considerations. Use "Additional Save Parameters" to detect you save in the participant and exit the participant.
Paul B selected this answer as the correct answer

Comments
Paul B commented Sep 10 '15, 5:26 a.m. | edited Nov 07 '15, 7:28 p.m.

 Hi Ralph,


Thanks again for your reply. I'll give this a shot tomorrow when I'm at work. So if I add these two lines

saveParameter.getAdditionalSaveParameters().contains.........

and 

Set additionalParams = new HashSet();
    additionalParams.add(IExtensionsDefinitions.UPDATE_PARENT_DURATION_EXTENSION_ID);
    workItemServer.saveWorkItem3(parent, null, null,additionalParams);
    
then I should be ok? It's searches for strings so I should be able to cast the set to type String and type whatever, as long as that's what I search for to stop recursive loop?

Also Ralph, lets say my example has this implemented. Will the above code update the fields I'm trying to update? Can it be done any better?

Thanks


Ralph Schoon commented Sep 10 '15, 5:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Really, really read the whole post. You also might have to refetch the work item to avoid stale data issues.

Only the line you mention just passes the additional save parameter. You also have to check in the beginning of the participant if this parameter is provided. If so, this indicates the participant runs as a result of its own save and you must exit the participant to terminate the recursion.


Paul B commented Sep 10 '15, 7:19 a.m. | edited Nov 07 '15, 7:29 p.m.

I will read the whole post, I'm just trying to get as much out of you as I can while your at work (different time zones). I thought the line below fetched the work item again and would prevent it from being stale :( I had a stale data issue and thought this would solve it. All I want to be able to do is modify a work item. I don't even know how to properly do this. I've read doco that has a link that tells me to read more doco and then another link to read more doco (I'm getting there but I'm running out of time).


All I want to know how to do is modify the current work item. How to properly get it, change an attribute or two, and save it! At work I'm going to read every word in the post you suggested cause I really need this working (I'm going to hold your forum cred to this :P ).

And thanks for help :) 

IWorkItem wc2 = workItemServer.findWorkItemById(workItem.getId(), IWorkItem.FULL_PROFILE, monitor);



sam detweiler commented Sep 10 '15, 7:33 a.m.

your participant is called cause someone else JUST changed the workitem, and then change process is not complete yet.  then in the middle of the last change, you create ANOTHER change.  now two in progress at once.

As Ralph said, you need to  use saveWorkitem3(), to pass the additional parm , so that you can check the additional parm on the participant invocation to avoid recursion.


Ralph Schoon commented Sep 10 '15, 7:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You load WC2 but then you modify and save WC.....


Paul B commented Sep 12 '15, 6:25 p.m.

I read this article and implemented using the same method as they did with my package as the string in the Set, and it it worked. It's alive.......ALIVE!


I think I have the fundamentals of RTC dev now to do what I need to do and grow from there.

Thanks for all your help.

showing 5 of 6 show 1 more comments

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.