It's all about the answers!

Ask a question

Setting / updating work item attribute value using the java api


Morten Madsen (3032341) | asked Nov 14 '12, 8:14 a.m.
edited Nov 14 '12, 8:18 a.m.
Hi, I've read a lot of the other posts about this, and I just can't get this to work.

I basically want to call "setValue(IAttribute, Object)" on a work item, and my approach is this:
EDIT: "att" is an IAttribute.
wi = (IWorkItem) jazzAPI.fetchCompleteItem(wi);
val = wi.getValue(att).toString();

sayln("Now processing work item ["+wi.getId()+"] with info ["+wi.toString()+"]");
WorkItemWorkingCopy workingCpy = jazzAPI.getWorkItemClient().getWorkItemWorkingCopyManager().getWorkingCopy(wi);
val = val.replaceAll(replaceFrom, replaceTo);
workingCpy.getWorkItem().setValue(att, val);

workingCpy.save(jazzAPI.monitor);


I can even print out the work item info, so I have the correct state:
Now processing work item [70] with info [Proxy of com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl@e880e88 (stateId: [UUID _dzLYICzAEeKnM9g6W2GS7g], itemId: [UUID _KyWLgCzAEeKuBMMvbWuwXw], origin: com.ibm.team.repository.client.internal.TeamRepository@7eca7eca, immutable: true) (contextId: [UUID _hPM_oCyrEeKuBMMvbWuwXw], modified: 2012-11-12 12:59:51.97, workingCopy: <unset>) (mergePredecessor: null, workingCopyPredecessor: <unset>, workingCopyMergePredecessor: <unset>, predecessor: [UUID _Uoz6ZizAEeKnM9g6W2GS7g]) (id: 70, internalState: BDworkflow.state.s3, internalResolution: , resolutionDate: null, summary: mybd, internalSeverity: , creationDate: 2012-11-12 12:58:50.47, internalPriority: priority.literal.l01, dueDate: null, description: asd, workflowSurrogate: , internalTags: , workItemType: bd, duration: -1, timeSpent: -1, internalSequenceValue: null, correctedEstimate: -1, startDate: null, archived: false)]


but I keep getting the error:
org.eclipse.core.runtime.AssertionFailedException: null argument:
	at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:85)
	at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:73)
	at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.getWorkingCopy(WorkItemWorkingCopyRegistry.java:739)
	at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyManager.getWorkingCopy(WorkItemWorkingCopyManager.java:98)
	at rtctool.RTCAdminTool.searchAttributeUsage(RTCAdminTool.java:291)
	at rtctool.RTCAdminTool.handleChoice(RTCAdminTool.java:141)
	at rtctool.RTCAdminTool.main(RTCAdminTool.java:95)

I get the error when I call .getWorkingCopy(). Any ideas?

Accepted answer


permanent link
Lauren Hayward Schaefer (3.3k11127) | answered Nov 15 '12, 7:53 a.m.
JAZZ DEVELOPER
Hi Morten,

I think you need to call manager.connect() before calling getWorkingCopy().  My code looks like this:

IWorkItemClient workItemClient= (IWorkItemClient)teamRepository.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager manager= workItemClient.getWorkItemWorkingCopyManager();
manager.connect(workItemHandle, IWorkItem.SMALL_PROFILE, progress.newChild(20));
IWorkItem workItem= null;
WorkItemWorkingCopy copy= manager.getWorkingCopy(workItemHandle);
workItem= copy.getWorkItem();
Morten Madsen selected this answer as the correct answer

Comments
Morten Madsen commented Nov 16 '12, 2:59 a.m.

IT WORKS!!! THANK YOU!! :-DD


Lauren Hayward Schaefer commented Nov 16 '12, 7:04 a.m.
JAZZ DEVELOPER

You're welcome! :-)

Your answer


Register or to post your answer.