Create a "Contributes To" link reference in CR workitem Programmatically.
How can I programmatically create a "Contributes To" link reference in CR workitem for each value configured in the "affected app workitem" attribute within CR. "Affected App WorkItem" is a custom attribute within CR which is of type workitem list. So I have created a follow up action sever side plugin. But I am unable to get the values of the custom attribute.
"com.ibm.team.workitem.ChangeRequest")) {
IAttribute attribute = null;
List<IAttributeHandle> attributesHandles = new ArrayList<IAttributeHandle>();
attributesHandles = sourceworkItem.getCustomAttributes();
Iterator<IAttributeHandle> attributesHandlesIterator = attributesHandles
.iterator();
if (attributesHandlesIterator != null) {
while (attributesHandlesIterator.hasNext()) {
IAttributeHandle currentAttributeHandle = attributesHandlesIterator
.next();
IRepositoryItemService itemService = getService(IRepositoryItemService.class);
IAttribute currentAttribute = (IAttribute) itemService
.fetchItem(currentAttributeHandle,
IRepositoryItemService.COMPLETE);
String currentAttributeID = currentAttribute
.getIdentifier();
if (currentAttributeID
.equalsIgnoreCase("affected_work_items")) {
attribute = currentAttribute;
break;
}
}
2 answers
See https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ for how to find an attribute using its ID. Also see https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
Thanks Ralph. Now I am getting the values of the attribute as DelegatingItemList. So tried iterating and the values are instance of IWorkItemHandle. Now I am confused how to get the workItem from the workItemHandle.
if (value instanceof List) {
List workItemList = (List) value;
for (Object item : workItemList) {
if (item instanceof IWorkItemHandle) {
IWorkItemHandle appWI = (IWorkItemHandle) item;
??????????????????????
appWI = (IWorkItem) appWI.getWorkingCopy();
// fetch work item links of the application Work Item
IWorkItemReferences appWIReferences = workItemServer
.resolveWorkItemReferences(appWI, null);
// add link of type PArent to existing child Task work item
appWIReferences
.add(WorkItemEndPoints.TRACKS_ITEMS,
Comments
You can read the links I9 provided and the links to the beginner sections. You have to fetch or resolve the work item handle. Search for resolve in my blog. IWorkItemCommon or IWorkitemServer should have a method that takes a handle or an array of handles and returns the work items..
There are also posts about linking work items in my blog. Consider searching my blog.
You use the IAuditableCommon Interface. wiCommon is an IWorkItemCommon in the code below.
Thanks Ralph. Yes it is working.