It's all about the answers!

Ask a question

How to close work item: setResolution2? How to use?

Martin Gompertz (3359) | asked May 08 '13, 7:47 p.m.
Is there any sample code for how to "close" a work item from a plain java client?  Probably I mean "resolve".

(In my way of thinking, I simply want to "change state" of the work item, but the most obvious API IWorkItem.setState2(...) is deprecated.)

Browsing the JavaDoc I find IWorkItem.setResolution2(Identifier<IResolution> value)

This looks likely to be what I need, but I can't see how it is to be used.

I guess a lot of Q&A could be reduced if there were more samples.  Thank you.  Sorry if it's there and I just missed it, but I did look.  There is one similar-looking previous post but it talks about something named WorkItemServer but nothing like that is listed in the PJC JavaDoc.

Thank you.

Accepted answer

permanent link
Ralph Schoon (54.7k23641) | answered May 16 '13, 7:42 a.m.
edited May 16 '13, 7:43 a.m.
IWorkItem.setResolution2(Identifier<IResolution> value) is - as far as i can tell - not what you are using to close a work item. This is probably only intented to set the resolution code to the resolution of the work item workflow state (the thing that shows right to the state e.g. 'Invalid', 'Works for me' or 'Won't fix').

As described in you have to bring the work item into a closed state e.g. into the resolved state, if your workflow has one. As described in the same article the workflow contains means to access the resolution action using
However, you have to bring the work item in a state where you can use it first, by using workflow actions available in the state you are. Again, I tried to explain that in the articles mentioned. Once you are in the state you want to be, you can set the resolution as well, using your code above and a valid resolution identifier.

Code to analyze the workflow and get a series of transitions is in

There used to be a setState2() method in the client API that you were able to set an arbitrary state regardless of where you were, but that was deprecated the last time I saw. The reason probably being that you would be cheating and violate the workflow, if there was no transition available from your current state to the target state.

Hope this helps.
Martin Gompertz selected this answer as the correct answer

Martin Gompertz commented May 16 '13, 9:11 a.m.

Thanks Ralph.  In fact I succeeded when I noticed in your first link (the same one posted by Millard) there was a section suggesting how to use the API from a plain client.

How nice it would be if the workitem API contained a .close() method.  That function is what I have just had to write myself.

Anyway, the job is done now, and thank you.  It would have taken much longer without your helpful articles.

One other answer

permanent link
Millard Ellingsworth (2.5k12431) | answered May 09 '13, 6:44 p.m.
While the other post is older, it likely points to the correct path. I doubt setResolution2() is what you want as a resolution is a "sub-state", if you will. For example, if an item is Closed, Fixed, Closed is the state and Fixed is the resolution (available because Closed is a resolved state). 

A work item is going to have a defined workflow -- a collection of states and transitions (actions) that move between the states. Ideally, you want to respect that (RTC may even require you to). Programatically, it may be possible that Resolved is not available from whatever state the work item is currently in. Ralph Schoon's blog is worth reading (and re-reading) if you want to work the the Plain Java Client API. Here's one of his posts on manipulating work item states.]]


Martin Gompertz commented May 10 '13, 9:14 a.m.

I checked Ralph's blog before posting here (I always do, it's a good resource), but I seem to have missed that article you linked.  I'll read more and post again.  Thanks!!

Martin Gompertz commented May 14 '13, 5:56 p.m. | edited May 14 '13, 6:07 p.m.

Deleted. Still working.

Your answer

Register or to post your answer.