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

How to update workitem custom attributes?

How to update workitem custom attributes values and save workitem on server side using operation participant ?
Any code example ?

0 votes



One answer

Permanent link
 You first need to get a reference to the work item being saved as part of the operation:
Object data = operation.getOperationData();
if(data instanceof ISaveParameter) {
	ISaveParameter saveParameter = (ISaveParameter) data;
	IAuditable newState = saveParameter.getNewState();
	if(newState instanceof IAuditable) {
		IWorkItem workItemNewState = (IWorkItem) newState;
You then need to get a reference to the attribute(s) you want to update:
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IAttribute customAttribute = 
		workItemServer.findAttribute(workItemNewState.getProjectArea(), "customAttributeId", null);
You then need to get a working copy of the work item you want to update:
IWorkItem workingCopy = (IWorkItem) workItemNewState.getWorkingCopy();
Lastly you need to update the value of the attribute and save the working copy:
workingCopy.setValue(customAttribute, "my new value");
workItemServer.saveWorkItem2(workingCopy, null, null);

Full code looks like this:
public void run(AdvisableOperation operation, IProcessConfigurationElement participantConfig,
		IParticipantInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
	Object data = operation.getOperationData();
	if(data instanceof ISaveParameter) {
		ISaveParameter saveParameter = (ISaveParameter) data;
		IAuditable newState = saveParameter.getNewState();
		if(newState instanceof IAuditable) {
			IWorkItem workItemNewState = (IWorkItem) newState;
			
			IWorkItem workingCopy = (IWorkItem) workItemNewState.getWorkingCopy();
			IWorkItemServer workItemServer = getService(IWorkItemServer.class);
			IAttribute customAttribute = 
					workItemServer.findAttribute(workItemNewState.getProjectArea(), "customAttribute", null);
			workingCopy.setValue(customAttribute, "my new value");
			workItemServer.saveWorkItem2(workingCopy, null, null);

		}
	}
}
	
	

0 votes

Comments

Thanks for reply Jared,

I tried your code but I was getting the following exception:

Exception running followup action.

An unhandled exception occurred during "testing participant".

Stale Data.

any help???

Remove the workItemServer.saveWorkItem2(workingCopy, null, null); line from the code. As the operation advisor is running in the current context so this method will be called automatically. Saving work item twice is causing error.

If I am not wrong this code you are running inside the server then I thin working copy is also not needed.

First remove the line above if not working then do something like this

IWorkItem workItemNewState = (IWorkItem) newState;

        IWorkItemServer workItemServer = getService(IWorkItemServer.class);
        IAttribute customAttribute = 
                workItemServer.findAttribute(workItemNewState.getProjectArea(), "customAttribute", null);
        workItemNewState.setValue(customAttribute, "my new value");

Hi praveen, as you said , I tried but it was not working , it wont give exception but the workitem was also not save custom attribute value .

any other help please ..........

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
× 1,701
× 9

Question asked: Aug 16 '12, 4:07 a.m.

Question was seen: 5,058 times

Last updated: Aug 16 '12, 8:08 a.m.

Confirmation Cancel Confirm