how to create workitems with custom attributes using plain java client
Hello,
I'm using the following article to create workitems from Plain Java Client:
https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation
It all works, but I would like to set some custom attributes during workitem creation. Let's assume I have the attribute name and ID. How can I do it?
I'm using the following article to create workitems from Plain Java Client:
https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation
It all works, but I would like to set some custom attributes during workitem creation. Let's assume I have the attribute name and ID. How can I do it?
Accepted answer
There is an api call that will give you a list of custom attributes.
List<IAttributeHandle> customAttributes = workItem.getCustomAttributes();
Then just iterate over that list and handle the ones you need.
for (IAttributeHandle attributeHandle : customAttributes) {
IAttribute attribute = (IAttribute) jazzServer
.getRepository()
.itemManager()
.fetchCompleteItem(attributeHandle,
IItemManager.DEFAULT, jazzServer.getMonitor());
+ attribute.getIdentifier());
if (attribute.getIdentifier().equals("justification")) {
workItem.setValue(attribute,some_value);
......
}
The IAttribute fetchCompleteItem call gets the attribute, then you can get the id (getIdentifier()) and set the attribute.
List<IAttributeHandle> customAttributes = workItem.getCustomAttributes();
Then just iterate over that list and handle the ones you need.
for (IAttributeHandle attributeHandle : customAttributes) {
IAttribute attribute = (IAttribute) jazzServer
.getRepository()
.itemManager()
.fetchCompleteItem(attributeHandle,
IItemManager.DEFAULT, jazzServer.getMonitor());
+ attribute.getIdentifier());
if (attribute.getIdentifier().equals("justification")) {
workItem.setValue(attribute,some_value);
......
}
The IAttribute fetchCompleteItem call gets the attribute, then you can get the id (getIdentifier()) and set the attribute.