It's all about the answers!

Ask a question

After work item type update/attribute sync the new attributes are not visible on work item object

Marko Tomljenovic (31643105) | asked Nov 24 '16, 5:52 p.m.
I have developed a tool for synchronizing the work item attributes. For that I am using the class listed at the end of this post.

If I run my (plain java) application that synchronizes work items in order to show up some new attributes it works fine if I run the tool and then open the browser for looking at the work items. That means the new work item attributes are appearing then in the browser.

But this is not what I want/need. I am running the below listed operation on a bunch of work items. In the same application session I want to access the newly appearing attributes. But these attributes are not available via API. When I ask the project area for the new attributes they are found. But when I then fetch the synchronized work items and call IWorkItem.hasAttribute(xyz) the new attributes are not found. I could imagine that the work item objet ct (before the sync) is somehow cached and then returned instead of work item with the new custom attributes.

Code for running the work item attribute synch:

import org.apache.logging.log4j.LogManager;
import org.eclipse.core.runtime.IProgressMonitor;


public class SynchronizeWorkItemOperation extends WorkItemOperation {

  private IWorkItemClient fWorkItemClient = null;

   * Parameterised constructor.
   * @param workItemClient , {@link IWorkItemClient} instance , must not be null
  public SynchronizeWorkItemOperation(final IWorkItemClient workItemClient) {
    super("Synchronize Attribute Schema of Work Items", IWorkItem.FULL_PROFILE);
    this.fWorkItemClient = workItemClient;

  public void execute(final WorkItemWorkingCopy workingCopy, final IProgressMonitor mon)
      throws TeamRepositoryException {
    IWorkItem workItem = workingCopy.getWorkItem();

    IWorkItemType type =
        this.fWorkItemClient.findWorkItemType(workItem.getProjectArea(), workItem.getWorkItemType(), mon);
    if (type != null) {
      this.fWorkItemClient.updateWorkItemType(workItem, type, type, mon);

Marko Tomljenovic commented Nov 25 '16, 12:00 p.m. | edited Nov 29 '16, 12:01 a.m.

I have some more details on the root cause.

The root cause is the synchronization done by the method

this.fWorkItemClient.updateWorkItemType(workItem, type, type, mon);
When debugging the method I can see that this method actually does nothing since the new custom attributes (introduced by new master pa) are not available in the "type" instance. Therefore actually nothing is done.
So it must have something to do with how the type instance is retrieved.

I am really out of ideas now.

Marko Tomljenovic commented Nov 25 '16, 12:04 p.m.

When debugging the same code in Eclipse client the method gets the updated work item type with the new attributes whereas in my plain java world it is not working.

Accepted answer

permanent link
Marko Tomljenovic (31643105) | answered Nov 29 '16, 4:45 p.m.
I partially found a solution for it.
In the end the reason for this is that the call ProcessClientService.refreshProcessCache() is not happening in my application when the project area working copy object is saved. In the save() method implementation of ProcessAreaWorkingCopy the above mentioned call is executed not in all scenarios though.

If I manually invoke the refresh... call in my code then it works fine.

I will be investigating why this call is not done automatically.
Ralph Schoon selected this answer as the correct answer

Ralph Schoon commented Nov 30 '16, 7:25 a.m.

 Thanks for sharing, Marko!

One other answer

permanent link
Ralph Schoon (62.9k33645) | answered Nov 25 '16, 2:43 a.m.
edited Nov 25 '16, 2:45 a.m.

I am unsure what your requirement really is. The code above seems to be identical to and has worked for me. 

If you want to access the new Attributes after the synchronize, I would suggest to exit the operation, use the work item handle to resolve the updated work item again with a refresh.

IWorkItem itemm = (IWorkItem) teamRepository.itemManager()
	.fetchCompleteItem(handle, IItemManager.REFRESH, monitor);

Marko Tomljenovic commented Nov 25 '16, 3:20 a.m.

That is what I was trying. But still the new attribute did not appear when calling IWorkItem.hasAttribute().
Actually the problem is happening in relation to the WCL tool.
We have integrated WCL into a framework that in this scenario:
1. Switches the master project area
2. Runs the synchronization
3. Wants to set some dedicated values to the new attributes.

But in step 3 WCL complains (correctly) that the attribute to be set is not existing in the work item.

Ralph Schoon commented Nov 25 '16, 4:04 a.m.

 I don't know the answer, unfortunately. I looked at and the code is really identical. 

Your answer

Register or to post your answer.