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

Problem in accessing enumeration in work item using client java API

HI All,
I am trying to get value of enumeration literal using java API. I referred this link to access enumeration values using java API.
but when I use IAttribute to fetch required attribute I am getting Null pointer exception.
IAttribute someAttribute= workItemClient.findAttribute(projectareahandle, "severity", null);
value of someAttribute variable in null.

IAttribute someAttribute= workItemClient.findAttribute(projectareahandle, "com.ibm.team.workitem.attribute.severity", null);
this code snippet also return value of someAttribute as null. Therefore further part of code is not executed.
Is there any other way to fetch attribute of type enumeration. Or am I doing something wrong here,?

following is complete code snippet of my program

IProjectAreaHandle projectareahandle = projectArea.getProjectArea();
        IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
        IWorkItem work = workItemClient.findWorkItemById(id, IWorkItem.FULL_PROFILE, null);
        IWorkItem workcopy = (IWorkItem)work.getWorkingCopy();
        IAttribute someAttribute= workItemClient.findAttribute(projectareahandle, "severity", null);
       
        Object value = workcopy.getValue(someAttribute);
       
        if(value instanceof Identifier)
        {
            Identifier literalID = (Identifier) value;
            IEnumeration enumeration = workItemClient.resolveEnumeration(someAttribute, null);
            List literals = enumeration.getEnumerationLiterals();
            for (Iterator iterator = literals.iterator(); iterator.hasNext();)
            {
                ILiteral iLiteral = (ILiteral) iterator.next();
                if (iLiteral.getIdentifier2().equals(literalID))
                {
                    String displayvalue = iLiteral.getName();
                    System.out.println("its value is "+displayvalue);
                }
            }
        }

in someAttribute value fetched is null therefore further part is not executed.

0 votes


Accepted answer

Permanent link
So what is the question? Note that you have to provide a valid attribute ID for the code to even work. The ID for Severity is com.ibm.team.workitem.common.model.IWorkItem.SEVERITY_PROPERTY which returns "internalSeverity". The ID you can look up in the process configuration is "com.ibm.team.workitem.attribute.severity" which you also should be able to use.
vikrant kamble selected this answer as the correct answer

0 votes

Comments

Hi Ralph,
Question here is about fetching attribute of type enumeration,
When following line of code is executed
IAttribute someAttribute= workItemClient.findAttribute(projectareahandle, "severity", null);
value of someAttribute variable is null.
this also happens when I pass complete Id as follow
IAttribute someAttribute= workItemClient.findAttribute(projectareahandle, "com.ibm.team.workitem.attribute.severity", null);

It is working fine when i pass attribute id of other attributes. Problem is when I pass Id of enumeration type attribute.

This works for me. Of course you have to pass a valid ID for the enumeration type attribute and not one that is not available. You also want to read carefully: https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ and consider hasAttribute().  Of course that also requires the attribute to be found and thus a valid ID to be passed in findAttribute(). Or iterate the attributes available and get the ID's. Or use A RTC WorkItem Command Line Version 3.0 to print the available attribute ID's.

Hi Ralph,
When I passed "internalSeverity"  as attribute Id it worked for me.
I don't know why it was not working when I was passing attribute Id as "com.ibm.team.workitem.attribute.severity" I got this attribute Id when we look up in the process configuration tab.
Any particular reason behind it?

I don't know. That ID - which also only shows up in the Eclipse client, the Web UI shows internalSeverity does not work for me either. So I don't know. In the WCL I created a mapping for these ID's - to map them to their internal ID. So I would suggest to use the ID's shown in the Web Admin UI.

Feel free to write a defect for this.

Hi Ralph,
Thank you for all your effort.

showing 5 of 7 show 2 more comments

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,942

Question asked: Nov 09 '15, 1:31 a.m.

Question was seen: 2,620 times

Last updated: Nov 09 '15, 5:23 a.m.

Confirmation Cancel Confirm