It's all about the answers!

Ask a question

How to set the value of Filed Against in Plain Java API?


Piotr Aniola (3.7k11738) | asked Feb 17 '14, 4:31 a.m.
Hello,

given a string containing the desired value of Filed Against, I would like to set it to an IWorkItem.
I am using Plain Java API.

Thank you in advance.

One answer



permanent link
sam detweiler (12.5k6195201) | answered Feb 17 '14, 7:21 a.m.
edited Feb 17 '14, 8:03 a.m.
WorkItemWorkingCopyManager wcmgr = IWorkItemClient.getWorkItemWorkingCopyManager();
wcmgr.connect(workItemHandle...);
WorkItemWorkingCopy wc = wcmgr.getWorkingCopy(workitemHandle);
WorkItem wi = wc.getWorkItem();

wi.setCategory(ICategory value);

wc.save();
wcmgr.disconnect(workItemhandle);
(You can also use the IWorkItemOperation class, it will connect and disconnect under the covers, making it look like a more atomic operation.. it cannot detect conflicts between multiple clients changing the same workitem at the same time)

to FIND the category,
Its a TREE, so take care that u search the whole tree..
CategoriesManager catManager = CategoriesManager.createInstance(IAuditableClient, IProjectAreaHandle, monitor);
CategoryTreeNode rootnode= catManager.getRoot();

rootnode.getChildren().... will get u the list of root level categories, then u have to search thru them to find the one that matches the text u have, or team area or ...

      for (CategoryTreeNode node : rootnode.getChildren())
            {
                if(node.getName().equalsIgnoreCase(your_text))
                   {
                   // found category
                   ICategory xx = node.getCategory();
                   }

Ralph probably has a category search function in one of his blog entries.  ;->

Comments
Piotr Aniola commented Feb 17 '14, 7:40 a.m.

Thank you, but how can I get an auditable client?


sam detweiler commented Feb 17 '14, 7:47 a.m. | edited Feb 17 '14, 8:03 a.m.

I fixed my snippet above, should have used the classname, not my variable name

  private static IAuditableClient auditableClient = null;

             auditableClient = (IAuditableClient) repository
                    .getClientLibrary(IAuditableClient.class);

Your answer


Register or 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.