It's all about the answers!

Ask a question

How do you assign an owner to children WIs automatically when saving a parent WI?


Taki Nakajo (1.1k2246) | asked Feb 12 '16, 2:32 a.m.
How do you assign an owner to children WIs automatically when saving a parent WI?

Accepted answer


permanent link
Kohji Ohsawa (595128) | answered Feb 12 '16, 2:52 a.m.
JAZZ DEVELOPER
Hi Take-san,

If you are talking about a custom followup action, I am doing like below. It doesn't work for a child WI which is created by a parent and you will need to add more exception handlings, but I think you can use this sample as a start point.

public void run(AdvisableOperation operation,
            IProcessConfigurationElement participantConfig,
            IParticipantInfoCollector collector, IProgressMonitor monitor)
            throws TeamRepositoryException {
       
        Object data= operation.getOperationData();
        ISaveParameter saveParameter = null;
        if (!(data instanceof ISaveParameter)){
            return;
        }
        saveParameter = (ISaveParameter) data;
         if (          (saveParameter.getAdditionalSaveParameters() == null)
                 ||
                 ((saveParameter.getAdditionalSaveParameters() != null)
           && (!saveParameter.getAdditionalSaveParameters().contains(Recursion)))
        ) {
            IWorkItem parent = (IWorkItem) saveParameter.getNewState();
            IContributorHandle owner = parent.getOwner();
            List<IWorkItemHandle> workItemHandleList = findChildHandle(saveParameter, monitor);
            if(workItemHandleList.isEmpty()){
                return;
            }
            IWorkItemServer workItemServer = getService(IWorkItemServer.class);
           
            Iterator<IWorkItemHandle> iter = workItemHandleList.iterator();
            while (iter.hasNext()){
                IWorkItemHandle workItemHandle = (IWorkItemHandle)iter.next();
                IWorkItem workItem = (IWorkItem) workItemServer.getAuditableCommon().resolveAuditable(workItemHandle, IWorkItem.FULL_PROFILE,
                                monitor).getWorkingCopy();
                workItem.setOwner(owner);
                workItemServer.saveWorkItem3(workItem, null, null, bypass);
            }
         }
    }
    private List<IWorkItemHandle> findChildHandle(ISaveParameter saveParameter,
            IProgressMonitor monitor) throws TeamRepositoryException {
       
        List<IWorkItemHandle> workItemHandleList = new ArrayList<IWorkItemHandle>();
        List<IReference> references = saveParameter.getNewReferences()
                .getReferences(WorkItemEndPoints.CHILD_WORK_ITEMS);
        if (references.isEmpty())
            return workItemHandleList;

        for (IReference reference : references){
            if (reference.isItemReference() && ((IItemReference) reference).getReferencedItem() instanceof IWorkItemHandle) {
                workItemHandleList.add((IWorkItemHandle)((IItemReference) reference).getReferencedItem());
            }
        }
        return workItemHandleList;
    }
Taki Nakajo selected this answer as the correct answer

One other answer



permanent link
Dinesh Kumar B (4.1k413) | answered Feb 12 '16, 3:46 a.m.
JAZZ DEVELOPER
Hi,

Below link shows updating parent, thought this may interest you... :
https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/

Regards,
Dinesh

Your answer


Register or to post your answer.