Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Setting / updating work item attribute value using the java api

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?

0 votes


Accepted answer

Permanent link
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

3 votes

Comments

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

You're welcome! :-)

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,927
× 411
× 233
× 14

Question asked: Nov 14 '12, 8:14 a.m.

Question was seen: 7,719 times

Last updated: Nov 16 '12, 7:04 a.m.

Confirmation Cancel Confirm