How to get value of Custom Attributes in RTC extensions ? a simple example of text field can help me.
I'm writing RTC extensions for customized email rules. For sending an email to the owner I can't use the Owner built-in field. I need to use my own custom field(This is a requirement). I don't know how to read the custom field. I thought it would be easy like
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.
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
Start here https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
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.
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.