It's all about the answers!

Ask a question

How to fetch the Workitem (built-in / Custom) Attribute Id and Value?

ANIL ABRAHAM (2322024) | asked Sep 07 '12, 7:03 p.m.

Iam using

List<IAttributeHandle> List = sourceworkItem.getCustomAttributes;

it return StateId , UUID .

But i need "Attribute Id"

3 answers

permanent link
Lauren Hayward Schaefer (3.3k11727) | answered Sep 10 '12, 10:20 a.m.
edited Sep 10 '12, 10:20 a.m.
The following snippet should get you started: handle = workItem.getCustomAttributes().get(0); attribute = (IAttribute) teamRepository.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT, new NullProgressMonitor());
System.out.println("The attribute id: " + attribute.getIdentifier());
System.out.println("The value of the custom attribute: " + workItem.getValue(attribute));

ANIL ABRAHAM commented Sep 10 '12, 4:20 p.m.

Lauren , Thanks for your reply, But i could not resolve below a) "teamRepository" b) IItemManager c) NullProgressMonitor

PLease guide ?

Lauren Hayward Schaefer commented Sep 11 '12, 6:48 a.m. | edited Sep 11 '12, 8:58 a.m.

Hi Anil,

a) How you get the team repository depends on the context--if you're using the existing UI or if you're using a plain Java client.  The following wiki page contains examples on finding the team repository:
b) The ItemManager can be imported from
c) The NullProgressMonitor can be imported from org.eclipse.core.runtime.NullProgressMonitor.

ANIL ABRAHAM commented Sep 19 '12, 6:55 p.m.

ITeamRepository is a ClientSide interface . Since iam writing code in server side , i have difficulty.

Please send me some sample code to access the Attribute id and Value from Server side

Lauren Hayward Schaefer commented Sep 20 '12, 7:08 a.m.

I haven't tried this myself, but I believe the following code snippet taken from should work for you:

IAttributeHandle handle = workItem.getCustomAttributes().get(0); IRepositoryItemService itemService = getService(IRepositoryItemService.class); IAttribute attribute = (IAttribute) itemService.fetchItem(handle, IRepositoryItemService.COMPLETE);

permanent link
sam detweiler (12.5k6195201) | answered Sep 19 '12, 11:36 p.m.
here is my code from an advisor that loops thru the previous variable states (oldstate)

                // reference the right object type (cast)
                IWorkItem workItem = (IWorkItem) auditable;
                // get the worker objects
                IAuditableCommon iac = p.getSaveOperationParameter().getAuditableCommon();
                WorkflowManager wfm = new WorkflowManager(iac);   
                    IWorkItemCommon workItemCommon = iac.getPeer(IWorkItemCommon.class);
                    // loop thru all the attributes in the project
                    // attributes are project wide, not workitem specific
                    for(IAttribute ia:workItemCommon.findAttributes(p.getOldProcessArea().getProjectArea(), monitor) )
                        // if this attribute is available on this workitem
                            System.out.println("processing for variable="+ia.getDisplayName()+" attrib type="+ia.getAttributeType());
                                // attempt to get the enumeration literal for this attribute
                                // will throw exception if not an enum
                                IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemCommon.resolveEnumeration(ia, monitor);
                                    // get the literal specifically
                                    String[] iaval = ia.getValue(iac, workItem, monitor).toString().split(":");
                                    // if present
                                    if(iaval.length>1 && iaval[1]!=null)
                                        // loop thru the literal to value mappings                               
                                        for (ILiteral literal : enumeration.getEnumerationLiterals()) 
                                            // if this literal matches the attribute value
                                                // display the usable name
                                                System.out.println("attribute name="+ia.getIdentifier() +", type"+"="+ia.getAttributeType()+" literal="+literal.getIdentifier2().getStringIdentifier()+" literal name="+literal.getName());                                       
                            catch (Exception e)

ANIL ABRAHAM commented Oct 17 '12, 6:33 p.m.


It is Client Side or Server side Code ?

More over getPeer method is deprecated .

permanent link
ANIL ABRAHAM (2322024) | answered Oct 17 '12, 6:32 p.m.
Lauren, I replicated the same code above , IT DOESN'T WORKED. Any Sugg ? handle = sourceworkItem.getCustomAttributes().get(0);

IRepositoryItemService itemService = getService(IRepositoryItemService.


IAttribute attribute = (IAttribute) itemService.fetchItem(handle, IRepositoryItemService.


System.out.println (" Get Cust Attribute Display Name :" + attribute.getDisplayName());

System.out.println (" Get Cust Attribute Type :" + attribute.getAttributeType());

Lauren Hayward Schaefer commented Oct 18 '12, 6:44 a.m.

Hi Anil,
Can you elaborate on how this doesn't work?

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.