Retrieve history of work item states
I have the following code to begin retrieving the history of a work item using the plain java client.
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.
Steve
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.
Steve
3 answers
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.
Cheers.
what is 'defectId'?
the findWorkItemById is failing..
Sam
'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.