How to get value of Custom Attributes in RTC extensions ? a simple example of text field can help me.
![](http://jazz.net/_images/myphoto/c9958d4af00d6bb28320d13269d43c68.jpg)
String assigned_developer = workItem.getAttribute("assigned.developer").getValue();
where assigned.developer is the Id of the custom attribute.
Using the samples from the forum below code snippet I get Null pointer exception: I'm using this in Process advisor Sample code(which is working fine). The exception is in the first for(){}
IAuditableCommon iac = saveParameter.getSaveOperationParameter().getAuditableCommon();
@SuppressWarnings("deprecation")
IWorkItemCommon workItemCommon = iac.getPeer(IWorkItemCommon.class); //shows deprecated
//List<IAttributeHandle> wi_attribs = workItem.getCustomAttributes();
for(IAttribute ia:workItemCommon.findAttributes(saveParameter.getOldProcessArea().getProjectArea(), monitor) ) // this is where I get null pointer exception
{
System.out.println("\n For started 4444444! \n ");
if(workItem.hasAttribute(ia))
{
System.out.println("processing for variable="+ia.getDisplayName()+" attrib type="+ia.getAttributeType());
try
{
System.out.println("\n TRy started here!! \n ");
// this will throw exception if not enumeration
IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemCommon.resolveEnumeration(ia, monitor);
if(enumeration!=null)
{
String[] iaval = ia.getValue(iac, workItem, monitor).toString().split(":");
if(iaval.length>1 && iaval[1]!=null)
{
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals)
{
System.out.println("\n Second For here!! \n ");
if(literal.getIdentifier2().getStringIdentifier().equalsIgnoreCase(iaval[1]))
{
System.out.println("attribute name="+ia.getIdentifier() +", type"+"="+ia.getAttributeType()+" literal="+literal.getIdentifier2().getStringIdentifier()+" literal name="+literal.getName());
break;
}
}
}
}
}
catch (Exception e)
{
System.out.println("\n This is from CATCH started here!! \n ");
System.out.println("Exception="+e.toString());
}
}
}
Any help would be highly appreciated.
Accepted answer
![](http://jazz.net/_images/myphoto/c9958d4af00d6bb28320d13269d43c68.jpg)
There are many more examples on that blog, including https://rsjazz.wordpress.com/2015/02/25/a-rtc-workitem-command-line-version-2-1/
There are server examples as well.
Comments
![](http://jazz.net/_images/myphoto/c9958d4af00d6bb28320d13269d43c68.jpg)
Hi Ralph,
Thanks for the pointers. This was really a great help.The code from your workitem commandline example for getting the process area and the team repository handle really helped.
I used the common instead of the Client lib.
@SuppressWarnings("deprecation")
IWorkItemCommon workItemCommon = iac.getPeer(IWorkItemCommon.class);
//classification attribute
IAttribute myattr = workItemCommon.findAttribute(workItem.getProjectArea(), "my.attribute.id", monitor);
Object myattributevalue = workItem.getValue(myattr);
The above code works like a charm for string fields. I now have to extend it for enumerations.
Thanks again.
![](http://jazz.net/_images/myphoto/c9958d4af00d6bb28320d13269d43c68.jpg)
forgot to mention in the above code snippet
iac is IAuditableCommon
and getPeer() gives me deprecation warnings
![](http://jazz.net/_images/myphoto/e5e63d5878217b64611c1df9401b7cd3.jpg)
Anup, using the common API is a good move. I have to confess, sometimes it is hard to find the sweet spot.
Please don't use getPeer(). As in all the examples on my site a server extension for operational behavior typically extends AbstractService, which provides getService() to get the service interfaces.