It's all about the answers!

Ask a question

Create a "Contributes To" link reference in CR workitem Programmatically.


Chaithra Komath (11) | asked Mar 07, 2:38 a.m.

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.


    if (sourceworkItem.getWorkItemType().equalsIgnoreCase(
"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



permanent link
Ralph Schoon (63.3k33646) | answered Mar 07, 3:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Mar 07, 3:22 a.m.

permanent link
Chaithra Komath (11) | answered Mar 07, 7:27 a.m.

 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 (attribute != null) {
   Object value = sourceworkItem.getValue(attribute);

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
Ralph Schoon commented Mar 07, 12:07 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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..


Ralph Schoon commented Mar 07, 12:09 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

There are also posts about linking work items in my blog. Consider searching my blog.


Ralph Schoon commented Mar 08, 4:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You use the IAuditableCommon Interface. wiCommon is an IWorkItemCommon in the code below.


workItemList = wiCommon.getAuditableCommon().resolveAuditables(children, IWorkItem.FULL_PROFILE,
monitor);
 


Chaithra Komath commented Mar 08, 4:24 a.m.

Thanks Ralph. Yes it is working. 

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.