It's all about the answers!

Ask a question

[Precondition Plugin] Trying to create a plugin which checks the status of Related Change Request workitems and if any of the related change request workitems are not in closed group plugin will block the actual workitem from being closed.

Vikas Kumar (11) | asked Apr 05, 1:55 p.m.

I am trying to create a plugin which checks the status of Related Change Request workitems and if any of the related change request workitems are not in closed group plugin will block the actual workitem from being closed.

Problem: 1) Plugin is working fine if both the workitem A and workitem B are on same ccm.
                2) Plugin is throwing an exception if the workitem A and workitem B are on different ccm's.

Both 1) and 2) are working fine in my local server but case 2) is not working in our QA environment.
private List<IWorkItem> getRelatedChangeRequestWorkItems(IWorkItem target) throws TeamRepositoryException {
List<IWorkItem> returnVal = new ArrayList<IWorkItem>();
IWorkItemReferences references=null;

IAuditableCommon common = (IAuditableCommon)getService(IAuditableCommon.class);
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
// Get all references
        references = workItemServer.resolveWorkItemReferences(target, monitor);
        // Iterator<IEndPointDescriptor> endpoints = references.getTypes().iterator();
        //while (endpoints.hasNext()) {
        //IEndPointDescriptor endpoint =;
            // Iterator<IReference> allReferences = references.getReferences(endpoint).iterator();
        // Get the DependsOn references
        Iterator<IReference> allReferences = references.getReferences(ILinkTypeRegistry.INSTANCE.getLinkType(WorkItemLinkTypes.RELATED_CHANGE_MANAGEMENT).getTargetEndPointDescriptor()).iterator();
//            Iterator<IReference> allReferences = references.getReferences(WorkItemLinkTypes.RELATED_CHANGE_MANAGEMENT).iterator();
//        endPointDescriptor = ILinkTypeRegistry.INSTANCE.getLinkType(WorkItemLinkTypes.RELATED_CHANGE_MANAGEMENT).getTargetEndPointDescriptor().iterator();
            // Iterate across all DependsOn
            while (allReferences.hasNext()) {
            IReference reference =;
            //if (reference.getLink().getLinkTypeId().equals(linkType)) {     
        URI uri = reference.createURI();
    System.out.println(" Resolving URI: " + uri.toString());
    // get the location from the URI
    Location location = Location.location(uri);
    IItemType workitemType = location.getItemType();
    ItemProfile<IAuditable> createProfile = ItemProfile.createFullProfile(
    // resolve the item by location
    IAuditable referenced = common.resolveAuditableByLocation(
    location, createProfile, null);
    // look for a referenced work item
    if (referenced instanceof IWorkItem) {
    IWorkItem referencedWI = (IWorkItem) referenced;
    System.out.println(" Resolved URI (resolve): "
    + uri.toString() + " to: " + referencedWI.getId()
    + " " + referencedWI.getState2().toString());
        return returnVal;

Below is the exception that I am seeing in our QA:
Exception checking precondition. An unhandled exception occurred during "AllRelatedChangeRequestResolved".
CRJAZ0983E Unable to find Item identified by type "WorkItem" and identifier "1715362" 

Can anyone help me resolve the issue.

One answer

permanent link
Ralph Schoon (57.8k23642) | answered Apr 06, 2:20 a.m.
edited Apr 06, 2:21 a.m.

 You should be able to debug your extension to locate where the exception happens on Jetty. If not, follow the to learn how to. If you work on a 7.x version, drop me a note to with your e-mail and I will send you the current work in progress of the workshop update to 7.x.

Using the debugger and try/catch blocks you should be able to find the issue. The problem will very likely be the code that tries to access a work item on the remote server. The reason being that the API running in your local server has no access to the remote system. You would likely need OAuth and OSLC/REST APIs to be able to access the remote work item.

Note that there are pre-conditions/advisors e.g. the ones for guarding change set delivery, that might have example code in the SDK. 

Vikas Kumar commented Apr 06, 2:47 a.m.


I am working on 6.0.6 version. Plugin is working fine and fetching workitems from remote server in my local machine/server. I did debug it in my local server and have no issues. But I dont have access to our QA environment, thats why I am unable to debug the code in QA and I have issue in QA not in my local server. 
Yes, I guess we need Oauth to access the remote workitem. Can you please share example code of guarding changeset delivery if you have it handy. Meanwhile I will search for the examples.

Thank you  

Your answer

Register or to post your answer.