It's all about the answers!

Ask a question

workItem.hasAttribute(customAttribute) returning false, even though the work item contains the attribute?


James Williams (111) | asked Mar 06 '19, 5:55 a.m.
I am attempting to retrieve a custom attribute from a work item using the Plain Java API. Other custom attributes to our project area are being picked up, however this one is not.
            IWorkItemClient wiClient = (IWorkItemClient) teamRepo.getClientLibrary(IWorkItemClient.class);
            IWorkItem sample = wiClient.findWorkItemById(workItemNumber, IWorkItem.FULL_PROFILE, null);
            List<com.ibm.team.workitem.common.model.IAttribute> projectAreaAttributeList = wiClient.findAttributes(projectArea, new NullProgressMonitor());

for(IAttribute attribute: projectAreaAttributeList) {
log(attribute.getDisplayName());
if(sample.hasAttribute(attribute)) {
log("Work item has attribute:" + attribute.getDisplayName());
                } else {
                    log("Work item does not have attribute: "+ attribute.getDisplayName());


    
                }


    
            }

In the above example I am retrieving all the attributes for our project area. The attribute I am trying to retrieve is in this list, as it's display name is logged from the "log(attribute.getDisplayName())" call. However, it is then logged that the work item doesn't have the custom attribute. When I navigate to the work item through RTC, I can see the attribute and it is populated, however the call to "sample.hasAttribute(attribute)" still returns false in this case. Other custom attributes are retrieved and displayed correctly.

It's worth noting that this attribute is added to the work item upon completion, and isn't present in the work item from the very start of it's lifetime like the other custom attributes. I was wondering if this may be something to do with the problem.

Any help would be greatly appreciated, thank you!

One answer



permanent link
Ralph Schoon (63.3k33646) | answered Mar 06 '19, 6:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Mar 06 '19, 6:07 a.m.

 This does not make sense:


It's worth noting that this attribute is added to the work item upon completion, and isn't present in the work item from the very start of it's lifetime like the other custom attributes. I was wondering if this may be something to do with the problem.

A work item has the attribute or it does not. That the value is not set should have no impact on the "hasAttribute". 
  1. If you create a new work item from the type that is supposed to have the attribute and you set a value, does the code work?
  2. If you create a new work item from the type that is supposed to have the attribute and you do not set a value, does the code work?
Old work items that were created before the attribute was defined do not have the attribute. Synchronize the attributes in this case. There is a API call addAttribute() that can add an existing attribute that is not available.

Use the ID to understand which attribute you are talking about. The display Name does not need to be unique.
 

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.