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

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.


    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;
}
}

0 votes



2 answers

Permanent link

 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/

0 votes


Permanent link

 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,

0 votes

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.


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

Thanks Ralph. Yes it is working. 

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
× 7,496
× 1,706
× 1,326

Question asked: Mar 07 '24, 2:38 a.m.

Question was seen: 673 times

Last updated: Mar 08 '24, 4:24 a.m.

Confirmation Cancel Confirm