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

Catching newly added child workitems before save

I am writing a precondition on workitem save.

When I add a child and try saving a workitem, my precondition should be fired and also check if this newly added child (but has not been saved) is also verified but its not fetched.

On the other hand, if I do "set parent" from the child side , then this precondition is triggered fine.

I use the code below:

private void findOffspring2(List<IWorkItemHandle> offSpring,
            AdvisableOperation operation, boolean isFactoryItemOnly,
            boolean recurse) throws TeamRepositoryException {
        auditableCommon = getService(IAuditableCommon.class);

        Object data = operation.getOperationData();

        if (data instanceof ISaveParameter) // from Workitem -> save operation
        {
            ISaveParameter saveParameter = (ISaveParameter) data;
            IWorkItemReferences ref = saveParameter.getNewReferences();
            List<IEndPointDescriptor> types = ref.getTypes();
            for (IEndPointDescriptor desc : types) {
                if (desc.getId().equalsIgnoreCase(CHILDREN)) // "children" is
                // an RTC/Jazz
                // string ID
                {
                    List<IReference> refList = ref.getReferences(desc);

                    if (refList.size() > 0) {
                        IReference iRef = refList.get(0); // Only one parent
                        Object obj = iRef.resolve();
                        if (obj instanceof IWorkItemHandle) // Only looking for
                        // Workitems.
                        {
                            IWorkItemHandle childHandle = (IWorkItemHandle) obj;

                            IWorkItem childWorkItem = auditableCommon
                                    .resolveAuditable(childHandle,
                                            IWorkItem.FULL_PROFILE, null);

                            if (!isFactoryItemOnly
                                    || (isFactoryItemOnly && isFactoryWorkItem(childWorkItem))) {
                                offSpring.add(childHandle);
                            }
                            if (recurse) {
                                findOffspring(offSpring, childWorkItem,
                                        isFactoryItemOnly, recurse);
                            }
                        }
                    }
                }
            }
        }
    }

0 votes

Comments

  Hi, I am not clear what the question is.

Hi,

When I add children to  a workitem and click save, my precondition is fired but is not able to find this new child reference, since the child is not saved yet.

Please help me catch this new child reference before save.


Accepted answer

Permanent link
Hi,

I was always under the impression you should be able to get the new references using saveParameter              .getNewReferences().getReferences()

For example

List<IReference> blockingDependencies = saveParameter
                .getNewReferences().getReferences(
                        WorkItemEndPoints.DEPENDS_ON_WORK_ITEM);

If this is not working, you might have to use a participant instead of a precondition.
geetu garg selected this answer as the correct answer

0 votes

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
× 10,937

Question asked: Oct 15 '12, 4:33 p.m.

Question was seen: 3,291 times

Last updated: Oct 16 '12, 2:20 a.m.

Confirmation Cancel Confirm