It's all about the answers!

Ask a question

Retrieve history of work item states

Steve Gates (9134) | asked Feb 14 '12, 4:55 p.m.
I have the following code to begin retrieving the history of a work item using the plain java client.

WorkItemClient workItemClient= (WorkItemClient) repository.getClientLibrary(WorkItemClient.class);
IWorkItemClient iWiClient = (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class);
IWorkItem workItem = iWiClient.findWorkItemById(defectId, IWorkItem.FULL_PROFILE, monitor);

List<ChangeLogDTO> log = workItemClient.computeWorkItemHistory(workItem, monitor);

The issue I'm running into is that the last line of the snippet is throwing a null pointer exception. Not exactly sure why I'm getting that and hoping someone here would have some insight or if there's a better way.


3 answers

permanent link
SEC Servizi (97123357) | answered Jun 18 '12, 5:28 a.m.
edited Jun 18 '12, 5:39 a.m.
You get a NullPointerException because you cannot get an instance of the WorkItemClient.class with:
WorkItemClient  workItemClientInternal = (WorkItemClient) repository.getClientLibrary(WorkItemClient.class);
You have to use the constructor method:
WorkItemClient workItemClientInternal = new WorkItemClient((IClientLibraryContext) repo);
and where repo is your ITeamRepository current instance.

permanent link
Steve Gates (9134) | answered Feb 15 '12, 9:19 a.m.
what is 'defectId'?

the findWorkItemById is failing..


'defectId' is an int with a value of 7976, which is a valid work item ID in our database.

findWorkItemById is not failing because I can get the various values of the work item that are available with the workItem object, such as description, summary, etc.

permanent link
sam detweiler (12.5k6194201) | answered Feb 15 '12, 12:33 a.m.
what is 'defectId'?

the findWorkItemById is failing..


Your answer

Register or to post your answer.