It's all about the answers!

Ask a question

How to Set the Category (Filed Against) based on the Category of another Work item from Different Project area?


Muthukumar C (32712733) | asked Jun 11 '12, 7:26 a.m.
Hi,

I am having two work items each from different project area.
If am just assigning the Category from one WI to another

WorkItem1.setCategory(WorkItem2.getCategory());

I am getting "The category is not from the same project area as the work item." exception.

I have created the same Category in both the project areas. I want to get the Category from One project area and assign to work item of another project area with corresponding project area name.

Thanks

Accepted answer


permanent link
Ralph Schoon (61.1k33643) | answered Jun 11 '12, 8:57 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi,

since the category only exists in a project area you can't use the same object in another area. You have to get the string representation of the original category and find the matching category in the other project area. Then you can set the attribute with the result. Here some code from https://jazz.net/wiki/bin/view/Main/WorkItemExampleSource
 that is used in the examples to find a category based on a string representation.

        List<String> path = Arrays.asList(categoryName.split("/"));
        ICategoryHandle category = workItemClient.findCategoryByNamePath(
                projectArea, path, null);

Muthukumar C selected this answer as the correct answer

7 other answers



permanent link
Muthukumar C (32712733) | answered Jun 11 '12, 8:59 a.m.
edited Jun 11 '12, 9:00 a.m.
Ralph,

Its working fine. Thanks

Same way, I want to associate the PLANNED FOR field between work items of two project areas.
That is, i have created development iterations with same labels in both project areas. I want to select the same label from other project area.

Is it possible ? How?

Thanks

permanent link
Ralph Schoon (61.1k33643) | answered Jun 11 '12, 9:09 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi,

you basically have to follow the same strategy. You get the target from the original work item, then you use the string representation to find the iteration in the other project area and use workItem.setTarget(iteration) to set it. I have no example code for that, unfortunately.

permanent link
Muthukumar C (32712733) | answered Jun 11 '12, 9:11 a.m.
Thanks ralph.

I am already working on it
Will give you the sample code shortly if its working fine.

permanent link
Muthukumar C (32712733) | answered Jun 12 '12, 12:45 a.m.
Hi,

Using the code below, I am trying to map the Planned for field of two work items in diff project area. But, planned for filed is unassigned which means, condition is not met some where. Pls highlight any mistakes in the code,

        IDevelopmentLineHandle[] iDevelopmentLineHandle = projectArea.getDevelopmentLines();
        boolean breakfor;
        System.out.println("iDevelopmentLineHandle.length : " + iDevelopmentLineHandle.length);
        for (int i=0;i<iDevelopmentLineHandle.length; i++){
            IDevelopmentLineHandle iDevelopmentLinehndl = iDevelopmentLineHandle[i];
            IDevelopmentLine iDevelopmentline = (IDevelopmentLine) repositoryItemService.fetchItem(iDevelopmentLinehndl, null);
            IIterationHandle[] iterationHndls = iDevelopmentline.getIterations();
            breakfor = false;
            System.out.println("iterationHndls.length : " + iterationHndls.length);
            for (int j=0;j<iterationHndls.length; j++){
                IIterationHandle iterationHandle = iterationHndls[j];
                IIteration Destinationiteration = (IIteration) repositoryItemService.fetchItem(iterationHandle,null);
                System.out.println("Destinationiteration.getLabel() : " + Destinationiteration.getLabel());
                if(Destinationiteration.getLabel().equalsIgnoreCase(SourceIterationLabel)){
                    workItem.setTarget(Destinationiteration);
                    breakfor = true;
                    break;
                }
            }
            if (breakfor) break;
        }

permanent link
Ralph Schoon (61.1k33643) | answered Jun 12 '12, 5:47 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
The way this code works, you only catch the top level iterations. Iterations have children (getChildren()).

If you look for /Release1/Iteration 2/Endgame you have to split the string and search for Release 1 at the 1st level, Iteration 2 on the 2nd and Endgame below that.

permanent link
Muthukumar C (32712733) | answered Jun 12 '12, 6:11 a.m.
edited Jun 12 '12, 6:13 a.m.
Hi,

It seems that the Children again can have iterations and so on...
So, How many levels I need to dig to search the string???

process is becoming Tedious :(

Is there any function to get the IterationHandle using the given string irrespective of the LEVEL of Children??

permanent link
Ralph Schoon (61.1k33643) | answered Jun 12 '12, 6:24 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi,

there is no limitation in levels. It is a tree and hence recursive. The same applies for the iteration from your source work item.

What you have to do is:
At the source work item get the target. Resolve the iteration. Get the name or ID, get the parent iteration, get the name or ID. Continue until there is no parent. Regardless how you want to stare the information for mapping, you will end up with information like

Release 1; Iteration 2; Endgame

given the iteration names/ID's from the example.

You need to pass this to the matching operation. I would probably put the results into an ArrayList, that would help you to easily fetch the name/ID you search for passing it as parameter into the recursive descend.

I would search for ID and name. I would not use getLabel().

You are done if you found it or if you have not found it and you don't have input anymore.


Your answer


Register or to post your answer.