It's all about the answers!

Ask a question

How to get value of Custom Attributes in RTC extensions ? a simple example of text field can help me.


0
1
anup Gaur (1391335) | asked Feb 25 '15, 11:49 a.m.
edited Feb 25 '15, 11:53 a.m.
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.

Accepted answer


permanent link
Ralph Schoon (59.0k23642) | answered Feb 25 '15, 11:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.
anup Gaur selected this answer as the correct answer

Comments
Ralph Schoon commented Feb 25 '15, 11:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

anup Gaur commented Feb 26 '15, 4:01 a.m. | edited Feb 26 '15, 4:05 a.m.

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.



anup Gaur commented Feb 26 '15, 4:08 a.m. | edited Feb 26 '15, 4:09 a.m.

forgot to mention in the above code snippet
iac is IAuditableCommon

and getPeer() gives me deprecation warnings


Ralph Schoon commented Feb 27 '15, 10:36 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.

Your answer


Register or to post your answer.