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

Why does a programatically created custom attribute appear in the Database but nowhere else?

I created a custom attribute with the following code:

if (!teamNameExists(wiToUpdate)) {
IProjectArea projectArea = fetchProjectArea(wiToUpdate);
String identifier = Messages.getString("Attribute.Identifier"); //$NON-NLS-1$
String displayName = Messages.getString("Attribute.Display.Name"); //$NON-NLS-1$
String attributeType = Messages.getString("Attribute.Type"); //$NON-NLS-1$

IAttribute teamAttribute = getWorkItemCommon().createAttribute(
projectArea, identifier, attributeType, displayName,
monitor);

wiToUpdate.addCustomAttribute(teamAttribute);
IWorkItem workingWI = (IWorkItem) wiToUpdate.getWorkingCopy();
IStatus saveWorkItemStatus = getWorkItemServer().saveWorkItem2(
workingWI, null, null);
logger.info("Status of Attribute Save is: "
+ saveWorkItemStatus.toString());
}

When I opened the project that the work item was associated with and selected  the Process tab. I checked the Project Configuration > Configuration Data > Types and Attributes  and selected the correct Type. The custom attribute I had created and saved did not exist. However, when I attempted to manually enter the attribute, I got an error saying the attribute ID already existed. 

When I try to retrieve the custom attribute programatically, created with the code above, the workItem method getCustomAttributes() returns null.

0 votes



One answer

Permanent link
I've found that the project area must know about the attribute before it can "cleanly" be in the work item context.  I use this little ditty:

protected IAttribute getAttribute(IProjectAreaHandle area,
            String attributeId, boolean createIt)
            throws TeamRepositoryException {
        IWorkItemClient service = getWorkItemClient();
        IAttribute attribute = service.findAttribute(area, attributeId, null);
        if (null == attribute && createIt) {
            attribute = service.createAttribute(area, attributeId,
                    AttributeTypes.MEDIUM_STRING, attributeId, null);
        }
        return attribute;
    }

which seems to do the trick.   The above method is followed by a workItem.addCustomAttribute( returned attribute from above)


0 votes

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
× 11,053

Question asked: Apr 29 '13, 1:15 p.m.

Question was seen: 6,256 times

Last updated: Apr 29 '13, 5:03 p.m.

Confirmation Cancel Confirm