It's all about the answers!

Ask a question

Updating Work Item field values on Server

Dan Rivett (1211115) | asked Apr 22 '09, 8:09 a.m.
I've written an OperationParticipant that runs on the server as a follow-up action when a work item is saved. What I want to do is programmatically set some custom attribute values from within the OperationParticipant based on changes made by the user.

I've tried to use the following code (paraphrased below):

public void run(final AdvisableOperation operation, final IProcessConfigurationElement participantConfig, final IParticipantInfoCollector collector, final IProgressMonitor monitor) throws TeamRepositoryException
final ISaveParameter saveParameter = (ISaveParameter) operation.getOperationData();

final IWorkItem newState = (IWorkItem) saveParameter.getNewState();

final IAttribute customAttribute = ...

newState.setValue(customAttribute, "this new value is not saved unfortunately");

I've also tried setting a value on the working copy instead of on the work item directly, but that doesn't seem to work either.

Is setting a value in this operation partipant possible?

I saw that there is a method but that seems to be a client method and so thought that just by calling setValue() on the work item on the server it would be updated.

Any help would be appreciated. Many thanks.

One answer

permanent link
Nate Decker (37814561) | answered Jul 16 '14, 4:25 p.m.

I see this is a very old post, but in case anyone comes here looking for this I'll add a response on here.

I think there are several things that are missing in the above code. For one thing, you have to get the "working copy" of the work item, not just the "new state". So that would look like:

IWorkItem newState = (IWorkItem) saveParameter.getNewState();
IWorkItemServer wis = getService(IWorkItemServer.class);
IWorkItem WI_WorkingCopy = (IWorkItem) fWorkItemServer.getAuditableCommon().resolveAuditable(newState.FULL_PROFILE, null).getWorkingCopy();

Note that the above instance of IWorkItemServer necessitates adding "" to the prerequisites of the plugin.xml in the Manifest file. There are posts on how to do this elsewhere in these forums.

Then once you have the working copy, you modify that working copy in whatever fashion you choose. After making your modifications to the working copy, you have to save it for those changes to be committed to the database. That command looks something like this:

service.saveWorkItem3(WI_WorkingCopy, null, null, additionalParams);

Note that the "additionalParams" argument should contain a string that you can check for at the beginning of your follow-up action to prevent the follow-up action from being triggered by itself recursively. To set up your "additionalParams" variable, it should look something like this:

Set<String> additionalParams = new HashSet<String>();

At the beginning of your follow-up action, you should check for this string. That code would look something like this:

if(saveParameter.getAdditionalSaveParameters().contains("EnsureThisStringIsUniqueSoYouCanCheckItLater")) return;

sam detweiler commented Jul 16 '14, 4:29 p.m.

right.. the parms object is really a set of strings

see second answer here

Your answer

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